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