-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rejection turns into fulfillment #23
Comments
If you don't re-throw the error in the catch handler, it is … handled. This is just like how sync try/catch works. It's not an unexpected conversion; it's a conversion. Promises/A+ covers this fully; it makes no exception for undefined. |
Your code parallels: try {
throw new CancellationError();
}
//Imagine this syntax working
catch(CancellationError e) {
console.log("cancel");
}
console.log("fulfilled"); It looks like you want: try {
throw new CancellationError();
}
//Imagine this syntax working
catch(CancellationError e) {
console.log("cancel");
throw e;
}
console.log("fulfilled"); Which can be done: var r = Promise.pending();
r.promise.catch(Promise.CancellationError, function (e) {
console.log("cancel");
throw e;
})
.then(function () {
console.log("fulfilled");
});
r.cancel(); And gives:
|
Yes, I agree this makes sense, and I was simply confused. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has me puzzled, and I can't find justification for it in the Promise/A+ spec.
When I do the above I was expecting that I'd get "cancel" in the output, but I got "cancel" and "fulfilled".
It turns out this is because my rejection handler didn't return anything, so the return value of undefined was promoted into a fulfilled promise! I can't find anything in Promise/A+ that indicates this should happen. I would argue that if you don't return anything, the .then promise should take the state of the promise that triggered the .catch.
This would prevent a rejection from unexpectedly being converted to a fulfillment.
To work around the issue, I explicitly return Promise.rejected(reason) form the .catch callback, but this requires allocating a new promise. What I really want to say is 'just use the existing promise', but I don't see any way to do that.
The text was updated successfully, but these errors were encountered: