Events & Hooks¶
xcoreSDK provides two asynchronous pub/sub mechanisms:
- Events — broadcast notifications. Any plugin can subscribe; all subscribers receive the event.
- Hooks — interceptor pipeline. Handlers run in priority order; a handler can stop propagation.
@on_event¶
Subscribes an async method to a named event pattern.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
event_name |
str |
— | Event name or glob pattern (user.*, *.created) |
priority |
int |
50 |
Execution priority; higher numbers run first |
once |
bool |
False |
Auto-unsubscribe after first delivery |
Wildcard patterns¶
@on_hook¶
Registers an async method as a hook handler. Hooks differ from events in that they run sequentially in priority order and can carry a result or block propagation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
hook_name |
str |
— | Hook name or glob pattern |
priority |
int |
50 |
Execution order; lower numbers run first |
once |
bool |
False |
Auto-unregister after first call |
timeout |
float \| None |
None |
Per-handler timeout in seconds |
Event¶
Event is the object passed to all event and hook handlers.
HookResult¶
Returned by hook handlers to signal success, failure, or propagation control.
EventMixin¶
Registered automatically by AutoMixin. Scans the plugin class for @on_event-decorated methods and subscribes them to self.ctx.events during on_load.
You rarely need to interact with EventMixin directly — use @on_event on your methods and AutoMixin handles the rest.
Manual emit¶
To emit events from within a plugin:
HookMixin¶
Registered automatically by AutoMixin. Scans for @on_hook-decorated methods and registers them with self.ctx.hooks during on_load.
All hook registrations are cleaned up automatically in on_unload.