Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Rejected CancelTokens #30

Closed
bergus opened this issue Jul 23, 2016 · 2 comments
Closed

Rejected CancelTokens #30

bergus opened this issue Jul 23, 2016 · 2 comments

Comments

@bergus
Copy link

bergus commented Jul 23, 2016

The cancel function passed to the executor of a CancelToken is the [[resolve]] function of its .promise.
This does let us do weird things like

const rejectedToken = new CancelToken(resolve => resolve(Promise.reject(…)));
const cancelledToken = new CancelToken(resolve => resolve(Promise.cancel(…)));

Are there any use cases for this? They don't make much sense to me.
The first one would probably only lead to a huge lot of unhandled rejections. Are token subscribers expected to deal with this?

@domenic
Copy link
Member

domenic commented Jul 23, 2016

This is to preserve the invariant that token.promise is not a promise for a promise.

@bergus
Copy link
Author

bergus commented Jul 23, 2016

I see. In my approach I just used a token.subscribe(…) method instead of token.promise.then(…) where the callback is called directly with the cancellation reason - no promise resolution involved at all.
Of course that means that you'd have to do getEvent().then(cancel) instead of cancel(getEvent()), but I figured the latter is uncommon enough and doesn't provide any advantages.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants