0

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?

3
  • what you mean with which method? Commented Aug 20, 2013 at 15:26
  • async.times Commented Aug 20, 2013 at 15:26
  • @AndreasHultgren that should be an answer and not a comment as it fully answers OP's question. Commented Aug 20, 2013 at 15:27

1 Answer 1

2
async.times(4, function(n, next){
    somethingAsync(n, next);
},
function (err) {
    // Here when all four calls are done
});

See async.times.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.