chancy.hub module

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

Bases: object

Parameters:
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, body)[source]

Emit an event with the given body.

Parameters:

event (str)

on(event, f)[source]

Register a handler for an event.

Parameters:
on_any(f)[source]

Register a handler for any event.

Parameters:

f (Callable[[Event], Awaitable[None]] | Callable[[Event], None])

remove(event, handler)[source]

Remove a handler from an event.

Parameters:
remove_on_any(handler)[source]

Remove a handler from any event.

Parameters:

handler (Callable[[Event], Awaitable[None]] | Callable[[Event], None])

async wait_for(event, timeout=None)[source]

Wait for a specific event to occur.

Parameters:
  • event (str | list[str]) – The name of the event to wait for, or a list of events.

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

Return type:

list[Event]