>
> Is there a reason to use a Promise as the cancellation token, rather than
> have something that is synchronously inspectable?
>

The only real downside of coming up with a new interface is that we have to
standardize it.  : )  It's a core protocol.

I agree that using a promise directly would feel awkward without a helper
library.  You'd probably also want a method that would throw an error if
the cancel token was activated (as in .NET
https://msdn.microsoft.com/en-us/library/system.threading.cancellationtoken.throwifcancellationrequested(v=vs.110).aspx
):

    cancelToken.throwIfCanceled();

Instead of the more verbose:

    if (cancelToken.canceled)
      throw new OperationCancelledError();

I also like the revealing constructor pattern that Domenic mentioned.  It's
almost good enough, as-is, for converting from a promise to a cancelation
token:

    new CancellationToken(cancel => somePromise.then(cancel));

Nice!
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to