chancy.hub module

class chancy.hub.Event(name: str, body: dict[str, any])[source]

Bases: object

body: dict[str, any][source]
name: str[source]
class chancy.hub.Hub[source]

Bases: object

An event hub for registering and emitting events.

clear()[source]

Clear all handlers.

async emit(event: str, body)[source]

Emit an event with the given body.

on(event: str, f: Callable[[Event], Awaitable[None]] | Callable[[Event], None])[source]

Register a handler for an event.

remove(event: str, handler: Callable[[Event], Awaitable[None]] | Callable[[Event], None])[source]

Remove a handler from an event.

async wait_for(event: str | list[str], timeout: float | None = None) list[Event][source]

Wait for a specific event to occur.

Parameters:
  • event – The name of the event to wait for, or a list of events.

  • timeout – The maximum time to wait for the event (in seconds).