I'm trying to run an async.each over an array of items.
For each item, I want to run an async.waterfall. See code below.
var ids = [1, 2];
async.each(ids,
function (id, callback) {
console.log('running waterfall...');
async.waterfall([
function (next) {
console.log('running waterfall function 1...');
next();
},
function (next) {
console.log('running waterfall function 2...');
next();
}],
function (err) {
if (err) {
console.error(err);
}
else {
console.log('waterfall completed successfully!');
}
callback();
});
},
function (err) {
if (err) {
console.error(err);
}
else {
console.log('each completed successfully!');
}
});
return;
The output for this code looks like:
running waterfall...
running waterfall function 1...
running waterfall...
running waterfall function 1...
running waterfall function 2...
running waterfall function 2...
waterfall completed successfully!
waterfall completed successfully!
each completed successfully!
But my intention is and my understanding is that the output should look like this:
running waterfall...
running waterfall function 1...
running waterfall function 2...
waterfall completed successfully!
running waterfall...
running waterfall function 1...
running waterfall function 2...
waterfall completed successfully!
each completed successfully!
I keep looking over the code and I don't know what's wrong, does anyone know if my code or my expectations for what the async methods should be doing is incorrect?
Thank you!