I am starting in nodejs. I am trying to understand a bit of code. This basically creates an event.
models / event.js
EventSchema.static("createEvent",function(event,user,callback){
var That = this;
async.waterfall([
function(callback){
var time = moment(event.releaseTime).tz(event.releaseTimezone).utc().toDate();
event.rTime= time;
callback();
},
function(callback){
var model = new That(event);
That.validateEvent(model,user,function(err){
if(err){
callback({message:err});
return;
}else{
callback(null,model);
return;
}
});
},
function(model,callback){
model.save(function(err,doc){
if(err){
callback({message:"Error saving event",err:err});
}else{
callback(null,doc);
}
});
},
function(savedEvent,callback){ }
I understood the first two callback functions, but did not understand the third and fourth.
The second callback says
callback(null,model);
and then the next callback starts with
function(model,callback){
The third callback says
callback(null,doc);
and then the next callback starts with
function(savedEvent,callback){
I do not understand this. Any help is appreciated.
source
share