CancelToken and Cancel Polyfill
This a polyfill of the polyfillable parts of the proposed cancellable promises spec.
See https://github.com/littledan/proposal-cancelable-promises for more details.
Use
import {CancelToken} from 'cancel-token';
const source = CancelToken.source();
const result = someCancellableApi(source.token);
eventSource.on('dont-care-about-result-anymore', () {
source.cancel();
});
const value = await result;
async function someCancellableApi(cancelToken) {
await doSomeWork(cancelToken);
cancelToken.throwIfRequested();
return doSomeMoreWork(cancelToken);
}
Developing
To test:
npm test
To watch source files and rerun tests when they change:
npm test:watch