Cancelable promise | github.com/Eazymov/cancel.it
The library will be exposed as a global Cancelable
variable
<script src="https://cdn.jsdelivr.net/npm/cancel.it@latest"></script>
or via unpkg
<script src="https://unpkg.com/cancel.it@latest"></script>
npm install cancel.it --save
yarn add cancel.it
A promise wrapper that provides possibility to create cancelable promises and wrap existing ones. Supports both TypeScript and Flow type annotations out of the box. Commonjs and es6-modules compatible
import Cancelable from 'cancel.it';
// This
const promise = new Promise((resolve, reject) => {
setTimeout(() => {
someCondition ? resolve(someValue) : reject(reason);
}, 1000);
});
// Turns into this
const cancelable = new Cancelable((resolve, reject) => {
setTimeout(() => {
someCondition ? resolve(someValue) : reject(reason);
}, 1000);
});
// OR
const cancelable = Cancelable.from(promise);
cancelable.isCanceled(); // false
cancelable.cancel();
cancelable.isCanceled(); // true
// Will never be fired
cancelable.then(/* ... */);
cancelable.catch(/* ... */);
cancelable.finally(/* ... */);
If you have any troubles, questions or proposals you can create the issue
Copyright (c) 2019 - present, Eduard Troshin