1.0.1 • Published 2 years ago

@daniele.fedeli/cancellable-promise v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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();
}
1.0.1

2 years ago

1.0.0

2 years ago