Cancellation architectural observations

Ron Buckton rbuckton at
Mon Mar 2 23:55:41 UTC 2015

The upside of having a separate abstraction for cancellation, is that it composes well with async functions:

async function runStockTicker(receiveSymbol, cancellationToken) {
  while (!cancellationToken.canceled) {
    var symbols = await fetchSymbols(cancellationToken);
    if (!cancellationToken.canceled) {
      for (var symbol of symbols) {
      await sleep(1000);

var stopTicker = new CancellationTokenSource();
runStockTicker(..., stopTicker.token);
stopTicker.cancel(); // stop the current fetch and the loop

From: es-discuss <es-discuss-bounces at> on behalf of Tab Atkins Jr. <jackalmage at>
Sent: Monday, March 02, 2015 6:21 PM
To: Kevin Smith
Cc: public-script-coord at; Dean Tribble; es-discuss
Subject: Re: Cancellation architectural observations

On Mon, Mar 2, 2015 at 3:18 PM, Kevin Smith <zenparsing at> wrote:
> I'm afraid I don't quite understand.  How is one supposed to create a
> cancelable task with async functions, under your proposed architecture?

I'm not sure!  The mapping between promises and async functions isn't
intuitive to me yet, and I'm not sure how async functions will be able
to produce promise subclasses rather than plain promises.

es-discuss mailing list
es-discuss at

More information about the es-discuss mailing list