-
Notifications
You must be signed in to change notification settings - Fork 12
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
Why not just have 'CancellationToken.race'? #13
Comments
The reason we have chosen the first API is that we have the ability to close a The second approach does not give us the ability to clean up registered callbacks. Given #12, we could consider amending the API as follows: class CancellationTokenSource {
...
constructor();
static race(linkedTokens: Iterable<CancellationToken>): CancellationTokenSource;
static all(linkedTokens: Iterable<CancellationToken>): CancellationTokenSource;
...
} This then parallels // similar to the first API above:
const source = CancellationTokenSource.race([token1, token2]);
const token = source.token; |
Some thoughts after reading this issue: const source = new CancellationTokenSource([token1, token2]);
const token = source.token; If we extend const source = CancellationTokenSource.race([token1, token2]);
const token = source.token; If one of the tokens is already canceled, we can return a constant object like |
The only problem with returning a constant object would have is if we opt to allow custom cancellation reason propagation. Returning a constant would not propagate the reason. However, given that you are describing a custom subclass this is perhaps less of an issue. |
If one of tokens is already canceled "we" can return the cancelled token itself. Like |
Closing this issue as the proposal no longer specifies cancellation behavior. See #22 for the current thinking regarding cancellation. |
This question came up at the May, 2017 TC39 meeting, asking why we don't just have a
CancellationToken.race(tokens)
method instead of using the CancellationTokenSource contstructor:The text was updated successfully, but these errors were encountered: