I am new to nodejs programming. so be patient with me.
I have two nodejs modules. One passes passes a message to another nodejs module. the second processes it and pass result back to the first module.
method 1
first module
:
secondModule.callFunction(message, function(data){
//deal with the return message from the second module
})
:
second module
:
function callfunction(message, callback){
//asynchornous functions for processing
callback(data);
}
:
method 2
same thing but done using event emitters in the second module
first module
:
secondModule.callFunction(message){
})
secondModule.on('done_event', function(data){
//deal with the reply
});
:
second module (uses event emitter)
:
function callFunction(message){
//asynchornous functions for processing
self.emit('done_event', data);
}
:
Are they both correct. what is the difference in these things (both are asynchornous) or have i done something stupid.
Thanks in advance