JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2674
  • Score
    100M100P100Q116364F
  • License MIT

A Promise lib for abortable.

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

NPM version node version

NPM download NPM count License

Promise lib for aborting in chain.

Features

  • Abort promise
  • Abort in promise chain
  • Abort nesting promise
  • Return promise after abort

Browser Support

Any browser that supports Promise.

Chrome Firefox Safari Opera Edge
33 ✔ 29 ✔ 8 ✔ 20 ✔ 12 ✔

If run in others, use Babel, 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/es5.min.js"></script> <!-- 1KB, recommend -->
<script src="https://unpkg.com/promise-abortable/dist/es6.min.js"></script> <!-- 1KB -->
<script src="https://unpkg.com/promise-abortable/dist/polyfill.min.js"></script> <!-- 19KB -->

Usage

// 1. Ininstantiation
const promise = new AbortablePromise((resolve, reject, signal) => {
  // 2. Set abort handler
  signal.onabort = reason => {
    // 4. `reason` is from `promise.abort(reason)`
  };
});
// 3. Invoke `signal.onabort(reason)`
promise.abort(reason);

Pseudo code

See full examples here.

Promise abort

const promise = new AbortablePromise(...);
promise.abort();

Clain abort

const promise = new AbortablePromise(...).then(...).catch(...);
promise.abort();

Nesting abort

const promise = new AbortablePromise(...).catch(value => {
  return new AbortablePromise(...);
});
// promise1 pending
promise.abort();  // abort promise1 and run catch
// promise2 pending
promise.abort();  // abort promise2

Promise after abort

const promise = new AbortablePromise(...);
promise.abort().then(...).catch(...);

Promise.all abort

const promise = AbortablePromise.all([...]);
promise.abort();

Promise.race abort

const promise = AbortablePromise.race([...]);
promise.abort();