Skip to content

rune.timer

Timers run actions after a delay or at a fixed interval. For a task-oriented introduction, see Timers.

rune.timer.after(seconds, action, opts?) -- one-shot: fires once, then removes itself
rune.timer.every(seconds, action, opts?) -- repeating: fires every interval
rune.timer.cancel(name) -- alias of rune.timer.remove

Both constructors return a handle and accept the common options (name, group). Timer handles additionally accept h:cancel() as an alias of h:remove().

rune.timer.every(seconds, action, opts?) -> handle
  • seconds (number) — the interval, in seconds (fractions allowed).
  • action (string | function) — a command string sent on each firing, or function(ctx).
  • opts (table, optional) — common options.

Scheduling is fixed-interval: the next firing is scheduled the moment the previous one fires, regardless of how long the action takes to run.

rune.timer.every(60, "save", {name = "autosave"})

A string action is sent as a command. A function action receives a context table (ctx.name, ctx.group, ctx.type); ctx:remove() is how a repeating timer stops itself:

local ticks = 0
rune.timer.every(10, function(ctx)
ticks = ticks + 1
rune.send("look")
if ticks >= 5 then ctx:remove() end
end)

h:disable() suppresses firing without unregistering; h:enable() resumes. A repeating timer keeps its schedule while disabled and picks it back up on re-enable.

Standard registry management applies: rune.timer.enable/disable/remove(name), .cancel(name), .list(), .count(), .clear(), .remove_group(group) — see Registries. /timers lists everything.

Related: Timers guide · rune.trigger · rune.hooks · rune.group