NodeJS Event Emitters
Event Emitters are built into Node, and are for pub-sub, a pattern where a publisher will emit events, which subscribers can listen and react to. In Node jargon, publishers are called Event Emitters, and they emit events, while subscribers are called listeners, and they react to the events.
In the above example, the dog is the publisher/EventEmitter, while the function that checks the item was the subscriber/listener. You can make more listeners too:
There can also be multiple listeners for a single event, and even remove listeners:
If you want to listen to a event only once, you can use:
Which will remove the listener automatically without race conditions.