0

my api only allows a maximum of 10 requests every second. I am trying to keep under this rate limit with async library. I have tried multiple functions but none of them work.

Pauseconnect and connectStream opens an eventstream for each item. let me know if you need to see their code.

async.queue --doesn't wait.

var cargo = async.queue(function (task, callback) { 
        setTimeout(
            connectStream(task)
            , 50000);
        callback();
     }, 1);


    for(var j = 0; j < TeamList.length; j++) {

        cargo.push(TeamList[j], function (err) {  

     });

async.eachLimit --stops at 5 and doesn't progress

async.eachLimit(TeamList, 5, pauseConnect, function(err){
                if(err) {console.log(err);}
    });

rate-limiter -- runs through all of them without waiting

limiter.removeTokens(1, function() {
      for(var i=0; i< TeamList.length; i++){
            connectStream(TeamList[i]);
      }
    });

async.each-- doesn't wait just runs through all of them

async.each(TeamList pauseConnect, function(err){
                if(err) {console.log(err);}
    });
Username
  • 1,950
  • 2
  • 12
  • 21

2 Answers2

0

You're missing the callback in the async.each, it should be (for example)...

async.each(TeamList pauseConnect, function(err, callback) {
  if(err) {
    console.log(err);
  }
  return callback();
});
0

If anyone is curious this worked for me

async.eachLimit(TeamList, 5, function(team, callback){
        setTimeout(function(){
        connectStream(team);
        callback();
       }, (5000));
        }, function(err){
                if(err) {console.log(err);}

    });
Username
  • 1,950
  • 2
  • 12
  • 21