var p2 = new Promise(resolve => {
setTimeout(() => {
resolve()
}, 2000)
})
var p1 = new Promise(resolve => {
resolve(p2)
})
p1.then(data => {
console.log("p1")
})
p2.then(data => {
console.log("p2")
console.log("p1 status ", p1) // pending
Promise.resolve().then(() => {
console.log("here") // p1.then()
})
})
because the state of p1 is determined by the state of p2, and then, ah, when I call Promise.resolve (). Then ()
in p2.then ()
, the output will take precedence over p1.then ()
. Why? I guess the state of p1 will not be changed until the next event loop?
can you give me some advice? thank you very much.