简体   繁体   English

异步模块(async.waterfall)

[英]async module (async.waterfall)

I am using async.waterfall module. 我正在使用async.waterfall模块。 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? 有什么方法可以在结果中获取用户详细信息?

you can make the second callback return two parameters ex: datafromDB, notification 您可以使第二个回调返回两个参数,例如: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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM