forge.events¶
Decoupled, asynchronous module communication via an in-process event bus.
forge.events ¶
Event bus module — decoupled, asynchronous module communication.
Provides an in-process event emitter and subscriber system for modules to communicate without direct dependencies. Supports typed events, async handlers, lifecycle event hooks, wildcard pattern subscriptions, and an event history buffer for late-joining subscribers.
Attributes¶
Handler
module-attribute
¶
Signature that every event handler must satisfy.
Classes¶
EmptyPayload ¶
EventBusWrapper ¶
Wraps the core :class:~forge.core.events.EventBus with wildcard
pattern support and an event history buffer.
Every method is compatible with the core EventBus interface so
this class acts as a drop-in replacement for runtime._events.
Source code in src/forge/events/module.py
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
Attributes¶
Methods:¶
clear_history ¶
emit
async
¶
Emit event and await all registered handlers concurrently.
Stores the event in the history buffer, dispatches exact-match handlers via the core bus, and then dispatches wildcard handlers that match event.
Exceptions from individual handlers are caught and logged so that a failing handler never blocks other subscribers.
Source code in src/forge/events/module.py
has_listeners ¶
Return True if at least one handler is registered for event.
off ¶
Unregister a previously registered handler.
Raises KeyError if the handler is not registered for the
given event (or wildcard pattern).
Source code in src/forge/events/module.py
on ¶
Register an async handler for event.
Supports three calling conventions:
- Direct:
bus.on("event.name", handler) - Decorator:
@bus.on("event.name") - Wildcard:
bus.on("ai.*", handler)or@bus.on("*")
Wildcard patterns use shell-style globbing (fnmatch).
Source code in src/forge/events/module.py
replay ¶
Fire handler for every history entry that matches event.
Source code in src/forge/events/module.py
subscribe ¶
Register handler for event, optionally replaying matching history entries to the handler immediately.
This is the primary API for late-joining subscribers::
@runtime.events.subscribe("ai.*", replay=True)
async def track_ai(**kwargs):
...
Source code in src/forge/events/module.py
EventRecord
dataclass
¶
EventsModule ¶
Bases: ForgeModule
Forge module that upgrades the core EventBus with wildcard
subscriptions, history buffering, and late-joiner replay.
Register this module with the runtime early so that every other module can benefit from the enhanced event API::
runtime.register(EventsModule(history_size=500))