Skip to content

EventEmitterT

EventEmitter generic class

These objects expose an on() function that allows one or more functions to be attached to named events emitted by the object. When the EventEmitter object emits an event, all of the functions attached to that specific event are called synchronously. Any values returned by the called listeners are ignored and discarded.

Extends

  • EventEmitterTI<Events, this>

Extended by

Type Parameters

Events

Events emitted by EventEmitter

Constructors

new EventEmitterT()

new EventEmitterT<Events>(): EventEmitterT<Events>

Returns

EventEmitterT<Events>

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> })<Events>.constructor

Methods

addListener()

addListener<E>(event, listener): this

Adds the listener function to the end of the listeners array

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

listener: Events[E]

The callback function

Returns

this

This EventEmitter

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).addListener


emit()

emit<E>(event, …args): boolean

Synchronously calls each of the listeners registered for the event

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

• …args: Args<Events[E]>

Arguments passed to the listeners

Returns

boolean

True if the event had listeners, False otherwise

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).emit


eventNames()

eventNames(): (string | symbol | keyof Events)[]

List of emitter’s events

Returns

(string | symbol | keyof Events)[]

List of emitter’s events

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).eventNames


getMaxListeners()

getMaxListeners(): number

Maximum number of listeners per event

Returns

number

Maximum number of listeners per event

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).getMaxListeners


listenerCount()

listenerCount<E>(event): number

The number of listeners listening to the event

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

Returns

number

Number of listeners

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).listenerCount


listeners()

listeners<E>(event): Function[]

Copy of the array of listeners for the event

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

Returns

Function[]

Copy of the listeners array

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).listeners


off()

off<E>(event, listener): this

Removes the listener from the listener array for the event

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

listener: Events[E]

The callback function

Returns

this

This EventEmitter

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).off


on()

on<E>(event, listener): this

Adds the listener function to the event

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

listener: Events[E]

The callback function

Returns

this

This EventEmitter

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).on


once()

once<E>(event, listener): this

Adds a one-time listener function for the event

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

listener: Events[E]

The callback function

Returns

this

This EventEmitter

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).once


prependListener()

prependListener<E>(event, listener): this

Adds the listener function to the beginning of the listeners array

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

listener: Events[E]

The callback function

Returns

this

This EventEmitter

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).prependListener


prependOnceListener()

prependOnceListener<E>(event, listener): this

Adds a one-time listener function to the beginning of the listeners array

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

listener: Events[E]

The callback function

Returns

this

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).prependOnceListener


rawListeners()

rawListeners<E>(event): Function[]

Copy of the array of listeners for the event including wrappers

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

Returns

Function[]

Copy of the listeners array

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).rawListeners


removeAllListeners()

removeAllListeners<E>(event?): this

Removes all listeners, or those of the specified event

Type Parameters

E extends string | number | symbol

Parameters

event?: E

The name of the event

Returns

this

This EventEmitter

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).removeAllListeners


removeListener()

removeListener<E>(event, listener): this

Removes the specified listener from the listener array

Type Parameters

E extends string | number | symbol

Parameters

event: E

The name of the event

listener: Events[E]

The callback function

Returns

this

This EventEmitter

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).removeListener


setMaxListeners()

setMaxListeners(n): this

Sets maximum number of listeners per event

Parameters

n: number

Maximum number of listeners

Returns

this

This EventEmitter

Inherited from

(EventEmitter as { new<Events>(): EventEmitterTI<Events> }).setMaxListeners