impatient

A tool for turning asynchronous things into impatient versions of themselves
Install
npm installimpatient
Usage
var impatient = require('impatient');
var sleep = require('sleep-promise');
impatient(sleep(1000), 50 ).catch(function(err) {
console.error('promise rejection', err);
});
var impatientCb = impatient(function(cb) { setTimeout(cb, 1000); }, 50 );
impatientCb(function(err) {
console.error('callback error', err);
});
If you want to perform some cleanup on aborting, you may pass in a function as the 3rd param to impatient.
impatient(sleep(1000), 50, function() {
console.log('cleanup');
}).catch(function(err) {
console.error(err);
});
var impatientCb = impatient(function(cb) { setTimeout(cb, 1000); }, 50, function(cb) {
console.log('cleaning up cb');
cb();
});
impatientCb(function(err) {
console.error('callback error', err);
});
License
MIT © Allain Lalonde