silverbullet/website/API/event.md

31 lines
918 B
Markdown
Raw Normal View History

2025-01-17 03:41:52 +08:00
# Event API
The Event API provides functions for working with SilverBullet's event bus system, allowing communication between different parts of the application.
## Event Operations
### event.dispatch_event(event_name, data, timeout)
Triggers an event on the SilverBullet event bus. Event handlers can return values, which are accumulated and returned to the caller.
Example:
```lua
-- Simple event dispatch
event.dispatch_event("custom.event", {message = "Hello"})
-- Event dispatch with timeout and response handling
local responses = event.dispatch_event("data.request", {id = 123}, 5000)
for _, response in ipairs(responses) do
print(response)
end
```
### event.list_events()
Lists all events currently registered (listened to) on the SilverBullet event bus.
Example:
```lua
local events = event.list_events()
for _, event_name in ipairs(events) do
print("Registered event: " .. event_name)
end
```