Skip to content
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

Cancellation allows late catch and finally consumers #1121

Closed
dwelle opened this issue Jun 1, 2016 · 2 comments
Closed

Cancellation allows late catch and finally consumers #1121

dwelle opened this issue Jun 1, 2016 · 2 comments

Comments

@dwelle
Copy link

dwelle commented Jun 1, 2016

Not only late catch/finally observers are allowed, but catch handler shouldn't be called for cancelled promises.

Promise.config({ cancellation: true });
var p = new Promise(() => {});
p.cancel();
p.catch(() => console.log("catch") );
p.finally(() => console.log("finally") );

v 3.4.0, FF 46.0.1, Chrome 50

@spion
Copy link
Collaborator

spion commented Jun 1, 2016

Bluebird cancellation semantics are precisely like that. Only operations prior to cancellation are fully aborted: any handlers attached after the cancellation event will be rejected with a cancellation error.

More information is available here: #415

@dwelle
Copy link
Author

dwelle commented Jun 1, 2016

From docs:

As shown in the example the handlers registered with .finally are called even if the promise is cancelled. Another such exception is .reflect(). No other types of handlers will be called in case of cancellation.

Thus I gather, .catch handlers shouldn't be called neither when registered prior to cancellation (currently they're not), nor when registered after cancellation (currently they are).

Note that it is an error to consume an already cancelled promise, doing such a thing will give you a promise that is rejected with new CancellationError("late cancellation observer") as the rejection reason.

Registering .then to cancelled promise throws, but registering .catch/.finally doesn't. To me this seems inconsistent.

EDIT: scrap that. I read it wrong. Registering late consumers returns a rejected promise rejects them, which explains the behavior with the above console logs (which mute the error). So the behavior is correct 😓

@dwelle dwelle closed this as completed Jun 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants