EventEmitter
class implements pub-sub design pattern, it is defined in events module.
Below
table summarizes the events provided by EventEmitter class.
Event
|
Description
|
This
event is emitted before a listener is added to its internal array of
listeners.
|
|
This
event is emitted after the listener is removed.
|
Below
table summarizes the methods provided by EventEmitter class.
S.No
|
Method and
Description
|
1
|
This
function add listener to this event.
|
2
|
This
function calls all the listeners registered for this event synchronously.
|
3
|
Returns
an array listing the events for which the emitter has registered listeners.
|
4
|
Returns
the current max listener value for the EventEmitter. You can set the maximum
listeners for an event to the emitter by calling ‘setMaxListeners(n)’. If you
do not set maximum listeners value explicitly, then the ‘EventEmitter.defaultMaxListeners’
value is used as default value.
|
5
|
Returns
a copy of the array of listeners for the event named eventName.
|
6
|
It
is an alias for emitter.removeListener(). It removes the specified listener
from the listener array for the event named eventName.
|
7
|
It
adds a listener to this event.
|
8
|
This
method adds one-time listener to this event. Even though the event emitted
more than one time, this listener called only once.
|
9
|
Prepend
a listener function to the beginning of the array for the event named
eventName.
|
10
|
Prepend
a one-time listener function for the event named eventName to the beginning
of the listeners array.
|
11
|
Remove
all listeners associated with this event.
|
12
|
Removes
the specified listener from the listener array for the event named eventName.
|
13
|
By
default, EventEmitter allows 10 macimum listeners to an event. You can change
this behavior using 'emitter.setMaxListeners(n)' method. The value ‘n’ can be
set to Infinity (or 0) to indicate an unlimited number of listeners.
|
14
|
This
method returns a copy of the array of listeners for the event named
eventName.
|
No comments:
Post a Comment