Skip to content

Create time bombs and listen for them to 💥

License

Notifications You must be signed in to change notification settings

autonomoussoftware/time-bombs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

time-bombs

Build Status bitHound Overall Score bitHound Dependencies bitHound Code Code Style Known Vulnerabilities

Create time bombs and listen for them to 💥

More detailed description or notes as needed.

Installation

$ npm install --save time-bombs

Usage

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)

API

timeBombs.create(timeout, handler)

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.

bomb.reset(newTimeout)

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.

bomb.deactivate()

Deactivate the bomb by clearing the current timer, if any.

License

MIT

About

Create time bombs and listen for them to 💥

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published