Anju
Anju

Reputation: 25

async module (async.waterfall)

I am using async.waterfall module. scenario : in first callback function I am populating the data from the DB and passing the output of that in second callback function where I am send a mail notification and then updating the DB with a mail flag.

Code :

async.waterfall(
function(callback){
   // data population code
},
function(datafromDB, callback){
    NotificationManager.sendEmailToUser('MAIL', variableDetails, email, callback); 
   // code to update the database
}],
  function(err,result){
   //callback
}

I want the user details in result which I should be getting in callback function once the code to update the database is called but before that while sending the mail callback function is getting resolved. Is there any way to get the user details in the result?

Upvotes: 0

Views: 42

Answers (1)

Maged Milad
Maged Milad

Reputation: 311

you can make the second callback return two parameters ex: datafromDB, notification

async.waterfall(
function(callback){
   // data population code
},
function(datafromDB, callback){
    NotificationManager.sendEmailToUser('MAIL', variableDetails, email, callback); 
    // code to update the database
    callback(null, datafromDB, notification);
}],
  function(err,result){
   //callback
}

Upvotes: 0

Related Questions