timeout library for callbacks
optionsOrTimeout
object
- options passedretry
- TRUE if the timedCallback should be re-called if it returns an errorretryTimeout
- timeout between retrying timed callbacktimeout
- kill timeout
number
- the timeout before killing the function call
hurryUp(function(next) {
//this will cause an error
setTimeout(next, 2000);
}, 1000).call(null, function(err, result) {
console.error("timeout has occurred!")
})
Here's an easier way to wrap around a method:
hurryUp(emitter.once, 1000).call(emitter, "connected", function(err, result) {
});
You can also use hurryup to run a callback multiple times until it succeeds, like so:
function isItReady(next) {
//async stuff here
next(new Error("no!"));
}
hurryUp(function(next) {
isItReady(next);
}, { retry: true }).call(null, function(err) {
console.log(err.message); //no!
});