My Process1() function has a database loop, so Process2() and Process3() calling more than once. Which function should I use in async, to wait for a for loop?
async.waterfall([
function(callback){
Process1(yyy, function(){
//process1 function has a for loop.
callback();
})
},
function(callback){
Process2(function(){
// so process2() is calling more than once
callback();
})
}
], function (callback) {
Process3()
});
Process1() :
function Process1(yyy, pass){
user.find({}).exec(function(e, users){
_.each(users, function(_user){
user.findOneAndUpdate(
{'_id' : user_id},
{$inc : {'xxx' : yyy}},
function(e){
!e && pass()
})
})
})
}
forloop. It has to.process2. Aren't there any solution? @Brad thanks.Process2won't run untilcallbackin the first closure is called.forloop do? Is it a series of DB calls? If not, then you can put the async to the db process.