Op — Is a simple and pretty utility to abort operations 🚏
It can be used to cancel all types of asynchronous operations, since the conventional mechanisms like promises, does not have a way to do it.
The other reason why you can use this small library is, for example p-cancelable is cool, but have a few problems when used in promises that return other promises, or in other espesific contexts. ope-abort, is totally agnostic to the logic of a promise and this makes it simpler to clearer and avoid side effects.
$ npm install ope-abort
Create a promise that can be canceled
const opAbort = require('op-abort')
const display = (each, oa) => new Promise((resolve) => {
const clear = setInterval(() => console.log('foo'), each)
oa.onAbort(() => {
clearInterval(clear)
resolve()
})
})
const oa = opAbort()
display(1000, oa)
setTimeout(oa.abort, 3000)
function createOperationAbort(): OperationAbort // This returns the next methods and properties
function abort(reason?: string): void
function onAbort(fn: (...args: any[]) => any): void
state: {
aborted: boolean // default false, state of abort operation
, reason: string // default null, reason of abortion
}