When using async.waterfall
within a for
loop, it appears that the for
loop iterates before the nested async.waterfall
finishes all its steps. How can this be avoided?
for(var i = 0; i < users.length; i++ ) {
console.log(i)
async.waterfall([
function(callback) {
callback(null, 'one', 'two');
},
function(arg1, arg2, callback) {
// arg1 now equals 'one' and arg2 now equals 'two'
callback(null, 'three');
},
function(arg1, callback) {
// arg1 now equals 'three'
callback(null, 'done');
}
], function (err, result) {
// result now equals 'done'
console.log('done')
});
}
Output
0
1
2
3
4
done
done
done
done
done
Desired Output
0
done
1
done
2
done
3
done
4
done
for
loop, but ratherasync.map
(or whatever you need) – Marijuana