EventEmitter

Node API: Event Emitter

The EventEmitter class is defined and exposed by the node:events module:

const EventEmitter = require('node:events');

All EventEmitters emit the event 'newListener' when new listeners are added and 'removeListener' when existing listeners are removed.

It supports the following option:

  • captureRejections It enables automatic capturing of promise rejection. Default: false.

Inheritors

Functions

Link copied to clipboard
abstract fun addListener(eventName: String, listener: EventListener)
abstract fun addListener(eventName: String, listener: Value)

Alias for emitter.on(eventName, listener).

Link copied to clipboard
abstract override fun close()
Link copied to clipboard
abstract fun emit(eventName: String, vararg args: Any?): Boolean

Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.

Link copied to clipboard
abstract fun eventNames(): List<String>

Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

Link copied to clipboard
abstract fun getMaxListeners(): Int

Returns the current max listener value for the emitter.

Link copied to clipboard
abstract fun listenerCount(eventName: String): Int

Returns the number of listeners listening to the event named eventName.

Link copied to clipboard
abstract fun listeners(eventName: String): List<EventListener>

Returns an array listing the listeners for the specified event.

Link copied to clipboard
abstract fun off(eventName: String, listener: Value)

Alias for emitter.removeListener(eventName, listener).

Link copied to clipboard
abstract fun on(eventName: String, listener: EventListener): EventEmitter
abstract fun on(eventName: String, listener: Value): EventEmitter

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added.

Link copied to clipboard
abstract fun once(eventName: String, listener: EventListener)
abstract fun once(eventName: String, listener: Value)

Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

Link copied to clipboard
abstract fun prependListener(eventName: String, listener: EventListener)
abstract fun prependListener(eventName: String, listener: Value)

Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added.

Link copied to clipboard
abstract fun prependOnceListener(eventName: String, listener: EventListener)
abstract fun prependOnceListener(eventName: String, listener: Value)

Adds a one-time listener function for the event named eventName to the beginning of the listener array. The next time eventName is triggered, this listener is removed, and then invoked.

Link copied to clipboard
abstract fun rawListeners(eventName: String): List<EventListener>

Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

Link copied to clipboard
abstract fun removeAllListeners()

Removes all listeners, or those of the specified eventName.

abstract fun removeAllListeners(eventName: String)

Removes all listeners, or those of the specified eventName.

Link copied to clipboard
abstract fun removeListener(eventName: String, listener: Value)

Removes the specified listener from the listener array for the event named eventName.

Link copied to clipboard
abstract fun setMaxListeners(count: Int)

Sets the maximum number of listeners for the emitter.