Package Exports
- promise-abortable
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (promise-abortable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
promise-abortable
Concept
abort != reject, reject in abort maually rather than automatically.
Features
- Abort in promise
- Abort in promise chain
- Abort for nesting promise
- Return promise after abort
Browser Support
Any browser that supports Promise.
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
33 ✔ | 29 ✔ | 8 ✔ | 20 ✔ | 12 ✔ |
Use Babel for other browsers, or include script polyfill.min.js
below.
Install
$ npm install promise-abortable
The IIFE build is also available on unpkg:
<script src="https://unpkg.com/promise-abortable/dist/iife.es5.js"></script> <!-- 1KB, recommend -->
<script src="https://unpkg.com/promise-abortable/dist/iife.es6.js"></script> <!-- 1KB -->
<script src="https://unpkg.com/promise-abortable/dist/iife.es3.js"></script> <!-- 16KB -->
Usage
// 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 `signal.onabort(reason)`
promise.abort(reason);
Pseudo code
See full examples here.
Abort in promise
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();
Abort in promise chain
const promise = new AbortablePromise(...).then(...).catch(...);
promise.abort();
Abort for nesting promise
const promise = AbortablePromise.resolve(...).then(value => {
return new AbortablePromise(...);
});
promise.abort();
Promise after abort
const promise = new AbortablePromise(...);
promise.abort().then(...).catch(...);