-
Notifications
You must be signed in to change notification settings - Fork 29
Don't use .promise.then for subscription #59
Comments
Thanks for your input, but the current direction is we're going with for cancel token subscriptions. We're not going to add another developer-facing subscription protocol to the language for single-occurrence events, even if it just wraps the promise as you describe. |
There is no "other" subscription protocol - it behaves the same as TBH, closing this issue without even trying to counter my arguments looks a lot like "Yeah, I can see this is the wrong direction but it's the one we decided on". Not what I expected of TC39. |
I'm in favor of keeping .promise it has been very useful when writing code with tokens. The fact it never rejects is as relevant as the fact Math.max never throws. The engine can instantiate the object lazily if it needs to. |
@benjamingr Can you post (or point to) such an example where |
I'm afk on mobile for a while and in Japan, I can post some examples on Oct 23rd but I posted some motivating examples earlier in this repo that use .promise |
I might be missing something, but all the good examples I remember on this repo that used |
Any place I want to resolve another promise with it, or pass it into a function - a promise is more powerful than a callback-taking API precisely because it's composable and I don't have to have the callback ready yet. |
@ljharb I don't think there are any common use cases where you'd want to pass a token's promise into a function instead of passing the token itself. If such use cases existed, making the token thenable could take care of them. |
There is no point in exposing a
.promise
on the token:CancelToken.race
(etc.) functions anyway notPromise.race(tokens.map(t => t.promise)).then(cancel)
token.promise.then(…)
is awkward, compared totoken.subscribe(…)
I guess I could find more.
What are the advantages of using a promise as part of a token? They allowed for quick prototyping (no need to reimplement all the subscription stuff) and they demonstrated the proposed semantics in a way everyone would be familiar with. I can't think of anything else. So - good for a draft, but nothing mature enough for the language.
My suggestion therefore is to remove the getter
and replace it by a method
Maybe the promise should be removed altogether even from the internals of
CancelToken
s, a [[CancelReason]] field of typeOption<Cancel<T>>
and a [[CancelReactions]] field of typeList<Function>
should suffice.The text was updated successfully, but these errors were encountered: