set_timeout: Timers

View source: R/app.R

set_timeoutR Documentation

Timers

Description

Run a function later (set_timeout()) or repeatedly (set_interval()). Timers are part of the event loop: callbacks run between events, never concurrently, and never block the interface. Widgets have their own widget$set_timeout() / widget$set_interval(), whose timers are cancelled when the widget is removed.

Usage

set_timeout(delay, callback, app = current_app())

set_interval(interval, callback, app = current_app())

Arguments

delay, interval

Seconds.

callback

⁠function(app)⁠.

app

The app; defaults to the running app.

Value

A Timer; call ⁠$cancel()⁠ to stop it.

Examples

clock <- app(label("", id = "clock"), bind("q", "quit"))
clock$set_interval(1, function(app) {
  app$query_one("#clock")$update(format(Sys.time(), "%H:%M:%S"))
})
if (interactive()) run(clock)

termr documentation built on Oct. 21, 2026, 5:13 p.m.