I am exploring Node.js.I understand that Node.js core API is built around the idiomatic asynchronous event-driven architecture Now, by this I guess it means every time an asynchronous Function is invoked, it registers this Function in some seperate async queue that under the hood is handled by a seperate thread by the Libuv . and the execution continues in the main program thread to the next line. now, when that asyc function has completed executing, will it 'Emit' some event OR just registers the callback into the Event Queue, that will be picked up by the Event loop eventually ? basically I am a little confused over understanding how distinct the concepts of general 'Events' and async callbacks (if they are called some events also).
Asked
Active
Viewed 320 times
1 Answers
0
As far as I'm aware, it's no different than addListener. There is some documentation on the event here: http://nodejs.org/docs/latest/api/events.html#emitter.on Both on and addListener are documented under the same heading. They have the same effect;
server.on('connection', function(stream) {
console.log('someone connected!');
});
server.addListener('connection', function(stream) {
console.log('someone connected!');
});
and .on() is exactly the same as .addListener() in the EventEmitter object.
Straight from the EventEmitter source code here:https://github.com/nodejs/node-v0.x-archive/blob/master/lib/events.js#L188
EventEmitter.prototype.on = EventEmitter.prototype.addListener;

Shekhar Tyagi
- 1,644
- 13
- 18
-
This does not seem to be what the OP is asking in their question. What you are mentioning here was covered awhile ago in [What is the difference between addListener(event, listener) and on(event, listener) method in node.js?](http://stackoverflow.com/questions/29861608/what-is-the-difference-between-addlistenerevent-listener-and-onevent-listen/29861649#29861649), though I don't think this is what the OP here is asking. – jfriend00 Apr 12 '17 at 07:05
-
Good Answer Tyagi . Thanks – Srini Apr 12 '17 at 14:35