A little lib for aborting in Promise chain.
npm install promise-abortable







abort != reject
- Abort in promise
- Abort in promise chain
- Abort for nesting promise
- Return promise after abort
Any browser that supports Promise.
!Chrome | !Firefox | !Safari | !Opera | !Edge |
--- | --- | --- | --- | --- |
33 ✔ | 29 ✔ | 8 ✔ | 20 ✔ | 12 ✔ |
- Use Babel for lower versions
- Or include script iife.es3.js below
- But I think bluebird 3 is a better choice
``bash`
$ npm install promise-abortable
`javascript`
import AbortablePromise from "promise-abortable";
The IIFE build is also available on unpkg:
`html`
`javascriptsignal.onabort(reason)
// 1. Instantiate
const promise = new AbortablePromise((resolve, reject, signal) => {
// 2. Set abort handler
signal.onabort = reason => {
// 4. Abort won't reject, but you can reject manually
};
});
// 3. Invoke `
promise.abort(reason);
`javascript`
const promise = new AbortablePromise(...);
// or: const promise = AbortablePromise.resolve(...);
// or: const promise = AbortablePromise.reject(...);
// or: const promise = AbortablePromise.all([...]);
// or: const promise = AbortablePromise.race([...]);
promise.abort();
`javascript`
const promise = new AbortablePromise(...).then(...).catch(...);
promise.abort();
`javascript`
const promise = AbortablePromise.resolve(...).then(value => {
return new AbortablePromise(...);
});
promise.abort();
`javascript`
const promise = new AbortablePromise(...);
promise.abort().then(...).catch(...);
`javascript``
const promise = new AbortablePromise(...);
(async () => {
try { await promise; } catch (error) {...}
})();
promise.abort();