Async.retry runs just before waiting for an interval

async.retry({times : 25,interval : 30000},myFunction.bind(functionData),function(err,results){
console.log("===================================")
console.log("Async function finished processing")
return;
})

myFunction is called immediately, and this is too 5 times, which is the default. also no waiting time between calls

+4
source share
2 answers

This is a version issue, I think.

Older versions async.retrycan only be called by the number as the first agent (for example, see v1.2.0 docs )

He does not accept the object opts. Therefore, if you pass it instead of the number for the first argument, by default it has no interval and the attempt count is 5.

v0.9.0 , 1.4.2 .

+2

. , times interval. :

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;
});

:

1
2
3
4
5
===================================
Async function finished processing

1

0

Source: https://habr.com/ru/post/1607066/


All Articles