跳转到正文

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 EventRegistration

SDK 说明:

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) -> bool

EventRegistration.__call__ ​

python
def __call__(self) -> bool

EventRouter ​

python
class EventRouter

SDK 说明:

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) -> EventRegistration

SDK 说明:

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) -> int

SDK 说明:

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') -> bool

SDK 说明:

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') -> bool

SDK 说明:

text
Alias for explicit dispatch; never consume another event source.

Neomega · 使用、开发与参考文档