Class FreeSwitchEventEmitter<E, T>
Type Parameters
- E extends string
- T extends Record<E, (arg: never) => void>
Constructors
constructor
- new FreeSwitchEventEmitter<
E extends string,
T extends Record<E, (arg: never) => void>,
>(
registerEvent?: (event: keyof T) => void,
unregisterEvent?: (event: keyof T) => void,
): FreeSwitchEventEmitter<E, T> Type Parameters
- E extends string
- T extends Record<E, (arg: never) => void>
Parameters
Optional
registerEvent: (event: keyof T) => voidOptional
unregisterEvent: (event: keyof T) => void
Methods
emit
- emit<K extends string | number | symbol>(
event: K,
arg: Parameters<T[K]>[0],
): boolean Type Parameters
- K extends string | number | symbol
Parameters
- event: K
- arg: Parameters<T[K]>[0]
Returns boolean
on
- on<K extends string | number | symbol>(event: K, handler: T[K]): this
Type Parameters
- K extends string | number | symbol
Returns this
once
- once<K extends string | number | symbol>(event: K, handler: T[K]): this
Type Parameters
- K extends string | number | symbol
Returns this
onceAsync
- onceAsync<K extends string | number | symbol>(
event: K,
): Promise<Parameters<T[K]>> Type Parameters
- K extends string | number | symbol
Returns Promise<Parameters<T[K]>>
removeAllListeners
- removeAllListeners(): void
Returns void
removeListener
- removeListener<K extends string | number | symbol>(
event: K,
handler: T[K],
): void Type Parameters
- K extends string | number | symbol
Returns void
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.