Skip to content
This repository has been archived by the owner on Jun 17, 2019. It is now read-only.

jomaxx/make-abortable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published