Cancellation architectural observations

Ron Buckton rbuckton at
Mon Mar 2 15:49:06 PST 2015

The simplest example is:


function doLater(callback, token) {

  var handle = setImmediate(callback);

  token.register(() => clearImmediate(handle));

var cts = new CancellationTokenSource();

doLater(..., cts.token);



If token registrations occur in a later turn, I have no way to clear the handle. I can write the following instead, however:


function doLater(callback, token) {

  setImmediate(() => {

    if (token.canceled) return;





But in this case, I still have a callback scheduled which may be unnecessary overhead. If this were a native API, we could chose to prioritize cancellation registrations over promise tasks. Even if the registrations are async, the cancellation signal would still need to be observable in a synchronous manner, even if only through reading the CancellationToken#canceled property.


From: Kevin Smith <zenparsing at>
Sent: Monday, March 02, 2015 6:42 PM
To: Ron Buckton
Cc: public-script-coord at; es-discuss
Subject: Re: Cancellation architectural observations


  *   Cancellation signals are produced by the caller and consumed by the callee.
  *   Observation a cancellation signal must happen immediately.

This is a crucially important question.  Can you elaborate on why you think this is the case?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list