javascript - Call variable number of functions in parallel? -


using async.parallel or custom control flow,

arr = [1, 2, 3, 4, 5, 3, 2, 3, 4, 5] //arr length  get_something = function(num, cb){   async_io(num, function (err, results){         cb()   });  }  

i want run get_something() on each member of array in "parallel". when they're finished i'd callback called results.

without async :

var n = arr.length, results = new array(n), oneisdone = function(index, result){    results[index] = result;    if (--n===0) callback(results); } arr.foreach(function(val i){      get_something(val, function(result){        oneisdone(i, result);     }); }); 

with async :

using async supposes asynchronous function accepts callback returning error first argument , result second, final callback :

async.parallel(arr, get_something, callback); 

if functions don't follow norm, you'll have make ugly wrappings.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -