Events¶
EventDispatcher ¶
Dispatches events to registered handlers.
Features: - Multiple handlers per event type - Error isolation: a failing handler does not affect others - off() to unsubscribe - Decorator mode: @dispatcher.on("a")
Source code in bidiwave/events/dispatcher.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
on ¶
on(event_type: str, handler: AsyncHandler | None = None) -> Subscription | Callable[[AsyncHandler], AsyncHandler]
Registers a handler for an event type.
If handler is None, acts as a decorator. If handler is provided, registers and returns a Subscription.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
str
|
Event type (e.g: "log.entryAdded"). |
required |
handler
|
AsyncHandler | None
|
Async function that receives the event. |
None
|
Returns:
| Type | Description |
|---|---|
Subscription | Callable[[AsyncHandler], AsyncHandler]
|
Subscription if handler is provided, decorator if not. |
Source code in bidiwave/events/dispatcher.py
off ¶
Unsubscribes a handler.
Source code in bidiwave/events/dispatcher.py
dispatch
async
¶
Dispatches an event to all subscribed handlers.
If a handler fails, the error is logged but not propagated (error isolation).
Source code in bidiwave/events/dispatcher.py
AsyncHandler
module-attribute
¶
Type for an async handler that receives an event.
Subscription
dataclass
¶
Handle to unsubscribe from an event.
Source code in bidiwave/events/handlers.py
unsubscribe ¶
Unsubscribes this handler from its originating dispatcher.
No-op if the dispatcher has already been garbage-collected.