I have two different events on a emitter where I need to set the maxlistener count dynamically. I have surfed many tutorials and docs but could not understand whether the count will be set to each individual event on the emitter or to all the events together it will be set to the particular count.
emitter.on('event1', function(){})
emitter.on('event2', function(){})
emitter.setMaxListeners(15);
When we use the above code will the max listener count set for both event1 and event2 combined to 15 or will it set listener count to each individual event to 15.
Eg:
Case 1:
event1 -- Max 15 listeners
event2 -- Max 15 listeners
OR
Case 2:
event1 listener + event2 listener -- Max 15 listeners?
Is it case 1 or case 2 that it sets?
Any help/suggestion is highly appreciated..
Thank you.
By default EventEmitters will print a warning if more than 10 listeners are added for a particular event.
It means that the limit is per event for an eventemitter.
The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.
Reference here
The Eventemitter setMaxListener
sheds more light.
By default, a maximum of 10 listeners can be registered for any single event. This limit can be changed for individual EventEmitter instances using the emitter.setMaxListeners(n) method.
Reference here.
Although it is not explicitly stated in the docs, it can be implied from the above two links