Skip to main content

React to events

Use filtered events when polling would lose ordering or waste work. A subscription belongs to the current run and has a bounded queue.

Subscribe to GUI changes

local changes = hexis.events.subscribe({
type = "gui.changed",
filter = {
screen = {generation = screen.generation},
after_revision = screen.revision,
slots = {12, 49},
},
})

The bundle needs events.gui.filtered. Use events.chat.filtered for a bounded matching chat subscription.

Wait for the next event

local next_event = hexis.events.next(changes, {timeout = 30})
if next_event.kind ~= "event" then return end

On GUI resync_required, take a fresh gui.snapshot and create a new subscription from its generation and revision.

Race an action against an event

local selected = hexis.select({action, changes}, {timeout = 30})
if selected.kind == "event" then
hexis.cancel(action)
end

hexis.select waits for the first candidate from a bounded list of action and subscription handles. Always inspect kind before reading result or event.

Close a subscription when it is no longer useful:

hexis.events.unsubscribe(changes)

Run cleanup also closes every remaining subscription.