1

I have a set of functions that are independent of each other [each of them returns a value, each of these functions also accept parameters.] and I wish to run them in parallel. If i use async.parallel I wont have the liberty to catch the values. Is there a way to do this?

Thanks.

4
  • The Async library actually does give you access to the results of the async functions. It's right in the docs: Second argument to async.parallel is callback(err, results) - An optional callback to run once all the functions have completed. This function gets a results array (or object) containing all the result arguments passed to the task callbacks. Commented Apr 21, 2014 at 10:24
  • Yeah, I tried that and it worked.But Thanks for writing by. Commented Apr 21, 2014 at 10:26
  • But yeah now i have a new problem, I want to pass some value to these functions, now async.parallels doesnt all me to pass function paramters. Commented Apr 21, 2014 at 10:27
  • 1
    For that you use async.each. Read the docs! Commented Apr 21, 2014 at 10:28

1 Answer 1

1

Example of how to do this in CoffeeScript:

async = require "async"
fns = [
   (cb) -> cb 1
   (cb) -> cb 2
   (cb) -> cb 4
]

async.parallel fns, (results) ->
  console.log results
  # produces [1,2,4]
Sign up to request clarification or add additional context in comments.

1 Comment

But what if i want to pass some parameters to the function.?

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.