Class EventEmitter<AllEvents>

EventEmitter

Portable implementation of the Node.js EventEmitter class

https://nodejs.org/docs/latest/api/events.html#events_class_eventemitter

Type Parameters

  • AllEvents = any

Constructors

  • Type Parameters

    • AllEvents extends {
          [event: string | symbol]: Listener<any>;
      } = any

    Parameters

    • options: {
          captureRejections: undefined | boolean;
          emitEventEmitterEvents: undefined | boolean;
      } = {}
      • captureRejections: undefined | boolean

        Capture rejections (not implemented)

      • emitEventEmitterEvents: undefined | boolean

        Emit 'newListener' and 'removeListener' events

    Returns EventEmitter<AllEvents>

Methods

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

    Type Parameters

    • E extends string | number | symbol
    • Args extends any[]

    Parameters

    • event: E

      The name of the event

    • Rest...args: Args

      The arguments to pass to the listeners

    Returns boolean

    true if the event had listeners, false otherwise

  • Removes the specified listener from the listener array for the event.

    removeListener() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener() must be called multiple times to remove each instance.

    Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution will not remove them from emit() in progress. Subsequent events behave as expected.

    Type Parameters

    • E extends string | number | symbol

    Parameters

    Returns EventEmitter<AllEvents>

    The instance this method was called on, useful for chaining