silverbullet/website/API/event.md

918 B

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:

-- 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:

local events = event.list_events()
for _, event_name in ipairs(events) do
    print("Registered event: " .. event_name)
end