Open nilptr opened 6 years ago
"adopt its state" means "permanently adopt its state" i.e. once you've adopted the state of p2, you ignore anything that would modify your own state, as you have already adopted the state of p2.
This is probably tied down more tightly in the ECMA Script specification, because that actually specifies how resolve
and reject
behave, but this spec only actually specifies what happens to values returned from .then
callbacks.
A test case like:
Promise.resolve(null).then(() => ({
then(resolve, reject) {
const p2 = new Promise((resolve1) => {
setTimeout(() => {
resolve1(1);
}, 1000);
});
resolve(p2);
reject(2);
}
})).then((value) => {
console.log('fulfilled:', value);
}, (reason) => {
console.log('rejected:', reason);
});
would actually be covered by the Promises/A+ specification. Your implementation must print "fulfilled: 1" to be Promises/A+
The specification says:
According to my understanding of these, when resolve p1 with p2, p1 will remain pending until p2 is fulfilled 1 second later, so p1 can be rejected with 2 immediately. However in Node.js / browser / bluebird these implementations, p1 adopts the state of p2. Which behavior is correct ?