Class EventBus<T, G>

EventBus class for managing event listeners and dispatching events.

Type Parameters

  • T extends O

    A record mapping event names to their payload types.

  • G extends O

    The game state type.

Constructors

Methods

Constructors

Methods

  • Dispatches an event to all registered listeners. Listeners with the same priority are executed concurrently. Propagation stops if any listener returns false.

    Type Parameters

    • K extends string | number | symbol

      The event name type.

    Parameters

    • eventName: K

      The name of the event to emit.

    • server: ServerBase<G>

      The server instance.

    • payload: T[K]

      The data associated with the event.

    Returns Promise<boolean>

    A promise that resolves to true if all listeners returned true, or false otherwise.

  • Removes a listener for a specific event. Can remove by listener function or by listener id.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • eventName: K

      The name of the event.

    • listenerOrId: number | ListenerFunction<T[K], G>

      The listener function or its unique identifier.

    Returns void

  • Adds a listener for a specific event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • eventName: K

      The name of the event to listen for.

    • listener: ListenerFunction<T[K], G>

      The callback function.

    • Optionalpriority: number = 0

      The priority of the listener. Higher priority listeners are executed first.

    Returns number

    A unique identifier for the listener.