Class FreeSwitchEventEmitter<E, T>

Inspired by https://danilafe.com/blog/typescript_typesafe_events/ but using Map, Set, adding once and an async version. typed-emitter no longer works properly.

Type Parameters

  • E extends string
  • T extends Record<E, (arg: never) => void>

Hierarchy (View Summary)

Constructors

  • Constructs a new event emitter.

    const ev = new FreeSwitchEventEmitter<'ping',{ ping: () => console.log('ping\) }>()
    

    Type Parameters

    • E extends string
    • T extends Record<E, (arg: never) => void>

    Parameters

    • OptionalregisterEvent: (event: keyof T) => void
    • OptionalunregisterEvent: (event: keyof T) => void

    Returns FreeSwitchEventEmitter<E, T>

Methods

  • Send out an event: all registered callbacks are notified.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K
    • arg: Parameters<T[K]>[0]

    Returns boolean

  • Register a new callback for the named event. The callback is called every time the event is emitted.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K
    • handler: T[K]

    Returns this

  • Register a new callback for the named event. The callback is only called the first time the event is emitted.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K
    • handler: T[K]

    Returns this

  • Returns a Promise that is resolved the next time the named event is emitted.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

    Returns Promise<Parameters<T[K]>>

  • Unregisters all callbacks from the named event.

    Returns void

  • Unregister the callback from the named event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K
    • handler: T[K]

    Returns void