cancelable-promise
Advanced tools
Changelog
3.0.0 (2020-04-07)
CancelablePromise
.
Now promises returned from Promise
API such as then
or catch
can cancel the root promise and all promises created from this root promise:// CancelablePromise v2
import CancelablePromise from 'cancelable-promise';
const promise = new CancelablePromise((resolve) => setTimeout(resolve, 1))
.then(() => console.log('callback2 executed'))
.then(() => console.log('callback3 executed'));
promise.cancel();
// logs:
// callback2 executed
// callback3 executed
// CancelablePromise v3
import CancelablePromise from 'cancelable-promise';
const promise = new CancelablePromise((resolve) => setTimeout(resolve, 1))
.then(() => console.log('callback2 executed'))
.then(() => console.log('callback3 executed'));
promise.cancel();
// no logs
import { cancelable } from 'cancelable-promise';
cancelable(new Promise((resolve) => setTimeout(resolve, 1)));
CancelablePromise
can be loaded in browser