I am trying to use nodejs async model for making async calls. here is a situation
Rough code in 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
your register function should take a callback which you call in the waterfall callback. Perhaps something like this: (sorry I don't do 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);
}
};