Interruptible timer
var { setInterrupt, clearInterrupt } = require('set-interrupt')
var i = setInterrupt(function (err, val) {
console.log('Hello world')
}, 1000)
// Never calls the callback
clearInterrupt(i)
// or
i.interrupt()
// Calls the callback with an error
clearInterrupt(i, new Error('Failed'))
// or
i.interrupt(new Error('Failed'))
// Calls the callback with a value
clearInterrupt(i, null, 'ok')
// or
i.interrupt(null, 'ok')
Creates a new interrupt
Cancels the interrupt timer. If you pass err
or val
, the callback is invoked
like a standard Node.js callback. Otherwise the callback is simply ignored.
If the timer has already been invoked, this becomes a noop
Convenience for the above, but behaves like clearTimeout
, ignoring itr
that
is not an interrupt
npm install set-interrupt