Am I best to avoid using more than one instance of an async module feature at a time?
My code has three parts to be performed in sequence. I'm using code like
var async = require('async');
async.waterfall(
[ function(cb) { part1(); },
function(cb) { part2(); },
function(cb) { part3(); }
],
function(err, res) { console.log('Done'); }
);
part1() has three parts, too. The third of those runs after the first two. My thought was to use
function part1(err, res) {
async.waterfall(
[ function(cb) {
async.parallel(
[ function(cb) { part1a(); },
function(cb) { part1b(); }
]
);
},
function(cb) { part1c(); },
function(cb) {
if (err) return err('part 1 error')
return res()
}
]
);
}
Where part1a and part1b are running, I'm using three features of async: the outer waterfall, and the waterfall and parallel in part1. I restructured part1 to use only one feature: a waterfall, part1a then part1b then part1c just to get it working.
I am not achieving success. For example, I haven't seen a message 'Done'. And when I restructured part1, I get a call on part1a, but not on part1b or any other.
Maybe I'm not alone. In Optional callback not being called in the node.js async module's forEachOf method, @LuisDelgado indicated, "As a personal note, I have not had so far success in having async work nicely with a function that has an internal callback-async function itself."
In Complicated use case for Node.js Async Module, @Robbie and @dark_shadow found some success with async.auto. I guess that would involve flattening my code by breaking my three outer level functions into their components and calling each component from the outer level. Maybe that's "the JavaScript way"!
What's right?
Thanks in advance ...
EDIT: Nice job, Adam Sax. Thanks lots! A follow-on ...
EDIT: Adam and others suggested promises. Adam likes bluebird and showed some useful syntax. I'm having trouble with bluebird, appealing though it is. I posted a follow-on bluebird question here. With this edit, I'm removing that follow-on, leaving this question (as the title suggests) as an async question.
For those encouraging me to use promises, thanks! Please see node.js, bluebird, poor control of execution path.
The async question remains: Am I best to avoid using more than one instance of an async module feature at a time?