我正在尝试使用nodejs异步模型进行异步调用。这是一种情况
Coffeee中的粗略代码
app.get '/register/email',(req,res)->
re = new require '/model/registerEmail'
re.register
## will the next line of code will be executed immediately if so what should be done
## to send the response..should I wait
class RegisterEmail
checkEmail: (cb)->
mongocall
saveMail: (cb) ->
mongocall
register: ->
async.waterfall([checkmail,savemail],(err,res)->
## how to send the error or response back to server
## since there is no response object access here
exports = RegisterEmail
答案 0 :(得分:0)
你的注册函数应该接受你在瀑布回调中调用的回调。也许是这样的:(抱歉,我不做CoffeeScript)
re.register(function(err, data){
if(err){
return res.send(500, err);
}
res.send(data);
};
var register = function(callback){
async.waterfall([checkmail, savemail], function(err, res){
if(err){
return callback(err);
}
callback(null, res.body);
}
};