-
Notifications
You must be signed in to change notification settings - Fork 1
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
CancelToken-likes? #3
Comments
The next question, after deciding what is a cancellation token, is what the constructor should do when something was passed but it's invalid. |
Doing anything besides "do nothing" would be a breaking change, since there are definitely existing scripts that return values in the executor. |
@ljharb But I don't know any scripts that pass something token-like as an argument besides the constructor. Of course it is a breaking change to introduce a second parameter, but I don't think it'll break anything. |
tc39/proposal-cancellation#22 looks like a step forward in this direction |
With tc39/proposal-cancellation#22, I would liken this to the behavior of |
The
Promise
constructor takes a cancellation token argument (and lots of other API functions take one and pass it through to the promise constructor).But what exactly should one be able to pass in there?
CancelToken
: sureCancelToken
subclasses: probably.requested
property: maybe, why not?Actually a
.requested
property is not exactly enough. We need a way to register a function that synchronously cancels the promise when the cancellation is requested.In the current proposal, RegisterPromise, CancelPromise and CancelFunction take care of this.
This also works for
CancelToken
subclasses, as they do have a [[RegisteredPromises]] slot as well.And with
.requested
properties we need to be cautious too. Currently it is expected that it changes state exactly only once, fromfalse
totrue
, and that when it does that happens in the process of calling CancelFunction. This ensures that we have no pending promises whose [[CancelToken]] is .requested, and that we have no cancelled promises whose [[CancelToken]] is not .requested. (Or at least not observably to scripts, the first situation actually happens during the call to CancelFunction).This already breaks apart for subclasses of
CancelToken
, who can overwriteget requested()
at their own discretion. For those instances, we can actually check their [[Result]] directly likeCancelToken.prototype.requested
does, to ensure that we don't believe in.requested
when it claimsfalse
despite the token being cancelled (see also #7 for related issues).This is not easily possible for arbitrary objects however.
The text was updated successfully, but these errors were encountered: