JSPM

make-abortable

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q15492F
  • License MIT

Make promises abortable! That's it! :)

Package Exports

  • make-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 (make-abortable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

make-abortable

Make promises abortable! That's it! :)

Install

# if using npm
npm i make-abortable
# if using yarn
yarn add make-abortable

Usage

const abortable = require('make-abortable');
const controller = new AbortController();
const signal = controller.signal;

const promise = new Promise(resolve => {
  setTimeout(() => {
    resolve();
  }, 1000);
});

// abortable(promise, controller) works as well
const abortablePromise = abortable(promise, { signal });

// abort the promise
controller.abort();

abortablePromise
  .then(() => {
    // this will not execute
  })
  .catch((err) => {
    if (err.name === 'AbortError') return;
    // handle real errors here
  });

AbortController

This library utilizes the AbortController api. This api is new so you might need a polyfill. Read about the AbortController api here.