Cancellation architectural observations

Kevin Smith zenparsing at gmail.com
Tue Mar 3 08:59:24 PST 2015


> function doLater(callback, token) {
>   var handle = setImmediate(callback);
>   token.register(() => clearImmediate(handle));
> }
>
> var cts = new CancellationTokenSource();
> doLater(..., cts.token);
> cts.cancel();
>

I'm not really clear about the ordering properties of setImmediate relative
to the promise microtask queue, but:

    function doLater(callback, cancelPromise) {
        let handle;
        cancelPromise.then(_=> clearImmediate(handle));
        handle = setImmediate(callback);
    }

This should work if setImmediate uses either the same MT queue as promises
or a lower-priority queue.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150303/33c39d69/attachment.html>


More information about the es-discuss mailing list