maverick.eventbus.EventBus#

class maverick.eventbus.EventBus(*, strict: bool = False)[source]#

Simple event bus for managing event subscriptions and emissions.

Parameters:

strict (bool) – If True, exceptions in event handlers will propagate. Otherwise, they will be logged.

__init__(*, strict: bool = False)[source]#

Methods

__init__(*[, strict])

emit(event, game)

Emit an event to all subscribed handlers.

subscribe(event_type, handler, *[, ...])

Subscribe to an event type with a handler.

unsubscribe(token)

Unsubscribe a handler using its token.

subscribe(event_type: GameEventType, handler: EventHandler, *, priority: int = 0, once: bool = False, mask: Callable[[Any], bool] | None = None) str[source]#

Subscribe to an event type with a handler.

Parameters:
  • event_type (str) – The type of event to subscribe to.

  • handler (EventHandler) – The function to call when the event is emitted.

  • priority (int) – Priority of the handler; higher priority handlers are called first.

  • once (bool) – If True, the handler will be removed after the first call.

  • mask (Optional[Callable[[Any], bool]]) – Optional filter function to determine if the handler should be called.

unsubscribe(token: str) None[source]#

Unsubscribe a handler using its token.

emit(event: GameEvent, game: Game) None[source]#

Emit an event to all subscribed handlers.