Keeps track of EventEmitter listeners and automatically removes them upon selected events. Useful when you want to avoid EventEmitter memory leaks caused by listeners not being removed.
const EventRegistry =const eventRegistry =const emitter =const otherEmitter =// Attach a listener using EventEmitter.prototype.on and remember it.eventRegistry// Attach a one-off listener using EventEmitter.prototype.on and remember it.eventRegistry// A single registry can track any number of event emitters.eventRegistry// When the 'end' event is emitted, remove all remembered listeners.// Note that this will also remove the progress listener from otherEmitter.eventRegistry
EventRegistry proxies the following functions to the
addListener(emitter, event, listener)AKA
on(emitter, event, listener)
once(emitter, event, listener)
removeListener(emitter, event, listener)
Additionally, it keeps track of every
listener passed. When a final event
occurs (see below), it will remove all of these listeners.
Marks the given
event on the
emitter as final. When that event occurs, all
listeners will be removed.
Undoes a call to
fin. Marks the
event on the
emitter as non-final.
onceFin(emitter, event, listener)
once(emitter, event, listener) followed by
Saves you a statement in this common scenario.
Removes all attached listeners and marks all final events as non-final. Basically what happens when a final event is emitted.