@daniele.fedeli/cancellable-promise
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Cancellable

codecov

Easy way to cancel async work in javascript

How to install

npm i @daniele.fedeli/cancellable-promise

How it works

The usage is pretty strightforward:

const Cancellable = require('@daniele.fedeli/cancellable-promise');
// const { Cancellable } = require('@daniele.fedeli/cancellable-promise');

const aLongRunningPromise = //

const { promise, abortController } = new Cancellable(aLongRunningPromise);

promise
  .then(console.log)
  .catch(console.error);

if(someCondition) {
  abortController.abort();
}

Is it possibile also to pass an abort controller along with the promise as parameters.

const Cancellable = require('@daniele.fedeli/cancellable-promise');
// const { Cancellable } = require('@daniele.fedeli/cancellable-promise');

const abortController = new AbortController();
const aLongRunningPromise = //
const args = {promise: aLongRunningPromise, abortController}

// If an abortController is passed, then only the promise is returned
const promise = new Cancellable(aLongRunningPromise);

promise
  .then(console.log)
  .catch(console.error);

if(someCondition) {
  abortController.abort();
}

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i @daniele.fedeli/cancellable-promise

    Weekly Downloads

    0

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    3.6 kB

    Total Files

    6

    Last publish

    Collaborators

    • daniele.fedeli