timeoutn
v1.0.2
Published
Simple library for taming timed out async work
Downloads
3
Readme
timeoutn
timeoutn is a simple library for taming timed out async work
Installation
$ npm install timeoutn
Basic Example
Here is a simple timed example. Where we call done callback before async work has finished.
var timeoutn = require('timeoutn')
, timedout
function done(err) {
if (err) {
console.log(err)
}
if (timedout()) {
return console.log('Handle timed out scenario here')
}
...
}
timedout = timeoutn(2000, done, 'Error processing after 2000 ms')
setTimeout(done, 3000)
Or you could just use err passed to handle, for timed out scenario
var timeoutn = require('timeoutn')
function done(err) {
if (err) {
return console.log(err)
}
...
}
timeoutn(2000, done, 'Error processing after 2000 ms')
setTimeout(done, 3000)
What's it good for?
Whenever you need to be sure that something has finished, and is not staling forever. You should setup timeout expectation and respond accordingly.
Running tests
$ npm install
$ npm test
Authors
License
BSD