tc39 / proposal-cancelable-promises

Former home of the now-withdrawn cancelable promises proposal for JavaScript
Other
375 stars 29 forks source link

Consider listening to cancelToken's promise in the await.cancelToken spec #43

Closed domenic closed 8 years ago

domenic commented 8 years ago

The current mechanism of tracking execution contexts is a bit weird. I did it because I thought the closure work would be weirder for the alternative. But now I am not so convinced, especially after writing Promise.withCancelToken which worked reasonably OK.

bergus commented 8 years ago

I already wanted to suggest that! That would be very similar to how I described CancelTokens in my proposal, btw - and I really like how they are getting closer to each other :-D.

bergus commented 8 years ago

Did you realise that this commit changed semantics?

domenic commented 8 years ago

Yes.

bergus commented 8 years ago

But why? Rejecting the promise immediately when you call cancel seems cleaner to me, without a asynchrony window for anything to interfere with the cancellation decision.

domenic commented 8 years ago

This version is actually implementable; storing execution contexts (a spec artifact) was not something that could be realistically implemented.

The difference should be barely noticeable since the await-ed promise also waits a turn. I guess we should move the waiting on the cancel token's promise to before the await-ed promise so that there's no possible way it can interfere.

bergus commented 8 years ago

You could have kept the old semantics by storing either the promiseCapability.[[Promise]] or the onRejected function in a list of the token, instead of the [[ExecutionContexts]]. That should've been just as implementable.

domenic commented 8 years ago

That's true. This version is simpler, however.