node.js - NodeJS + async: which control flow option to chose? -
as know, async.parallel, defined such code:
async.parallel([ function (callback) { callback(err, objects); }, function (callback) { callback(err, status); }, function (callback) { callback(err, status); }, ], function (err, results) { //smth results[n] array... });
performs tasks parallel. however, need callback result of first function (objects
, exact) avialable in 2nd , 3rd functions. in other words, first step – 1st function, second – ( 2rd + 3rd parallel results of 1st one). async.waterfall
seems bad idea 'cause:
- in waterfall function can't work parallel
- i can't access every result of stack, last.
any ideas? thanks!
you need both waterfall
, parallel
.
function thing1(callback) {...callback(null, thing1result);} function thing2a(thing1result, callback) {...} function thing2b(thing1result, callback) {...} function thing2(thing1result, callback) { async.parallel([ async.apply(thing2a, thing1result), async.apply(thing2b, thing1result) ], callback); } async.waterfall([thing1, thing2], function (error) { //all done });
Comments
Post a Comment