外观
event_router API
模块说明
text
Local routing for durable Event deliveries; no subscriptions or automatic ACK.EventHandler
python
EventHandler = Callable[['Event'], Awaitable[None]]EventRegistration
python
class EventRegistrationSDK 说明:
text
Unregister exactly one registration; repeated calls return False.EventRegistration.__init__
python
def __init__(self, router: 'EventRouter', registration: _Registration)EventRegistration.unregister
python
def unregister(self) -> boolEventRegistration.__call__
python
def __call__(self) -> boolEventRouter
python
class EventRouterSDK 说明:
text
Explicit, serial dispatch by Event.kind, in global registration order.
'*' matches any delivered kind locally; it does not grant Host subscriptions.
Handlers get the original Event. Failures/cancellation propagate immediately,
stopping remaining handlers without ACK or retry. Call from Plugin.on_event.EventRouter.__init__
python
def __init__(self, *, max_handlers: int=256)EventRouter.register
python
def register(self, kind: str, handler: EventHandler) -> EventRegistrationSDK 说明:
text
Add one async handler; duplicates are independent registrations.EventRouter.on
python
def on(self, kind: str) -> Callable[[EventHandler], EventHandler]SDK 说明:
text
Decorator that preserves the handler; remove it with off(kind, handler).EventRouter.off
python
def off(self, kind: str, handler: EventHandler | None=None) -> intSDK 说明:
text
Remove matching registrations and return their count.
Omitting handler removes all handlers for that exact kind. '*' selects
wildcard registrations, not registrations for every event kind.
An already running handler finishes; removed pending handlers are skipped.EventRouter.dispatch
python
async def dispatch(self, event: 'Event') -> boolSDK 说明:
text
True after at least one handler finishes; unmatched delivery is False.
Registrations added during dispatch start on the next delivery. Concurrent
or recursive dispatch raises instead of interleaving event side effects.
Worker normally serializes calls; this helper starts no tasks or listeners.EventRouter.feed
python
async def feed(self, event: 'Event') -> boolSDK 说明:
text
Alias for explicit dispatch; never consume another event source.