Create time bombs and listen for them to 💥
More detailed description or notes as needed.
$ npm install --save time-bombs
const timeBombs = require('time-bomb')
// create the first bomb
const bomb1 = timeBombs.create(100, function () {
console.log('This will not be called')
})
// deactivate it before it explodes!
setTimeout(function () {
bomb1.deactivate()
}, 50)
// create a second bomb
const bomb2 = timeBombs.create(100, function () {
console.log('This will be called in ~150ms')
})
// at 50ms, let it tick for 100ms more...
setTimeout(function () {
bomb2.reset()
}, 50)
Create a time bomb that will explode after the the given time in milliseconds. It will return the bomb
object.
If the bomb explodes, the handler
will be called with the bomb id as parameter.
Reset the bomb by changing its current timer to a new value. If no new time is given, it will default to the initial timeout set when the bomb was created.
Deactivate the bomb by clearing the current timer, if any.
MIT