Posts

Showing posts from May, 2015

Promises vs EventEmitters vs Callbacks

There is a lot of material online about these and I would try to keep it short and sweet to explain what is my current understanding of these. Promises are syntax to implement callbacks, so lets get rid of callback from the proportions. Now we are left with Promises vs EventEmitters . Internally or performance wise all are quite similar. So based on coding practices these are my observations: Promise : Promise are good abstraction of asynchronous commands which will happen in given amount of time. Making a db query is a promise, making a rest cal is a promise. Your code needs to wait for promise to be fulfilled. Lets give it an analogy,  a cab driver promises to come to pick you up at 6AM and when he fulfills the promise, you promise him to sit in the cab and reach office. I know analogy is little lame, but hope it explains the idea. EventEmitters : EventEmitters are used for truely async events, like someone clicked on a particular button on a page, or while operating