The retry is dependent on the callback within your function. If the first argument of the callback is not falsy, then it will retry based on your times
and interval
settings. For example:
var async = require('async');
var count = 0;
var functionData = { some: 'data' };
var myFunction = function(callback, results) {
console.log(++count);
process.nextTick(function() {
if (count < 5) { // Fail 5 times
return callback({ message: 'this failed' }, null);
}
callback(null, { message: 'this succeeded' });
});
};
async.retry({times : 25, interval : 1000}, myFunction.bind(functionData), function(err, results) {
console.log("===================================")
console.log("Async function finished processing")
return;
});
This outputs:
1
2
3
4
5
===================================
Async function finished processing
With a 1 second interval between each attempt
myFunction
? – Voucher