timeoutn is a simple library for taming timed out async work
$ npm install timeoutn
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)
Whenever you need to be sure that something has finished, and is not staling forever. You should setup timeout expectation and respond accordingly.
$ npm install
$ npm test
BSD