tc39 / proposal-cancelable-promises

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

CancelToken#or #68

Closed rictic closed 7 years ago

rictic commented 7 years ago

Feature proposal, as a lightweight alternative to await.cancelToken. Roughly equivalent to:

class CancelToken {
  or(thenable) {
    return new Promise((resolve, reject) => {
      this.promise.catch(reject);
      thenable.then(resolve, reject);
    });
  }
}

Usage:

async longRunning(cancelToken) {
  await cancelToken.or(uncancellableTask());
  await cancellableTask(cancelToken);
}