npm install stubborn
var Stubborn = require('stubborn');
var options = {
maxAttempts: 5,
delay: 1000
};
var stubborn = new Stubborn(task, options, callback);
stubborn.on('error', onError);
stubborn.run();
function task(callback) {
if (Math.random() > 0.2) {
callback('Task error');
} else {
callback(null, 'Task result');
}
}
function callback(err, result) {
if (err) {
console.error(err);
return;
}
console.log(result);
}
function onError(err) {
console.error(err);
}
- run
- error
- schedule
- maxAttempts