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

1.0.0 • Public • Published

Cancellable Promise

Basic Usage

const cancellablePromise = new CancellablePromise<LongRunningResult>((resolve, reject) => {
    
    resolve(runLongRunningProcess())
}, (reason: string) => {
    console.warn('request cancelled')
});

// cancel the promise if it runs longer than 10s
setTimeout(() => {
    cancellablePromise.cancel();
}, 10000)
console.log(await cancellablePromise);

Make a native Promise cancellable

const cancellablePromise = CancellablePromise.fromPromise(runLongRunningProcess());

// cancel the promise if it runs longer than 10s
setTimeout(() => {
    cancellablePromise.cancel();
}, 10000)
console.log(await cancellablePromise);

Readme

Keywords

none

Package Sidebar

Install

npm i @blakgeek/cancellable-promise

Weekly Downloads

113

Version

1.0.0

License

MIT

Unpacked Size

23 kB

Total Files

12

Last publish

Collaborators

  • carloslawton