Reputation: 26317
I'm looking to do something fairly simple with Nodejs and Async.
I have a number of pages
, say 4 for our example. And I want to make a request 4 times and then trigger a callback when they have all returned.
async.eachSeries new Array(pages)
,(i,next)->
offset+=100;
next();
,(err)->
console.log("All done!");
Is there an async method can I use a for loop in? Or do I need to loop over and create the functions first, and then pass to async?
Update: is the above the best way to do this?
Upvotes: 0
Views: 359
Reputation: 14953
async.times(4, function(n, next){
somethingAsync(n, next);
},
function (err) {
// Here when all four calls are done
});
See async.times.
Upvotes: 2