EventEmitter vs. Callbacks
Learn about the difference between EventEmitter and callbacks in Observer pattern.
We'll cover the following
A common dilemma when defining an asynchronous API is deciding whether to use an EventEmitter
instance or simply accept a callback. The general differentiating rule is semantic: callbacks should be used when a result must be returned in an asynchronous way, while events should be used when there’s a need to communicate that something has happened.
But besides this simple principle, a lot of confusion is generated from the fact that the two paradigms are, most of the time, equivalent and allow us to achieve the same results. Consider the following code as an example:
Get hands-on with 1200+ tech skills courses.