Skip to content

Docs menu // site/time

[ SDK ] /docs/sdk/time

site/time

Timers. Callbacks run later with a fresh step budget.

import
import time from "site/time"

Functions#

SignatureDescription
fn after(ms: i64, run: fn() -> void) -> i64once, after at least 100 ms
fn every(ms: i64, run: fn() -> void) -> i64repeatedly, at least 250 ms apart
fn cancel(id: i64) -> voidStops a timer, using the id that after or every returned.

Examples#

Timers
import site from "site"
import ui from "site/ui"
import time from "site/time"

var ticks = 0
var id = 0
id = time.every(1000, () => {
    ticks += 1
    site.readout("TICKS", "${ticks}")
    if ticks == 10 {
        time.cancel(id)
    }
})

time.after(2000, () => ui.toast("two seconds in", .Info))

Limits#

  • after waits at least 100 ms and every at least 250 ms; both at most 24 hours. Shorter values are raised to the minimum.
  • At most 20 timers live at once. every timers pause while the tab is hidden and resume when it is shown.
  • A callback that faults, or a timer whose callback has gone, stops repeating.
  • Each callback runs with a fresh step budget.

Declaration file#

This page is generated from the file below, served as /eitri/sdk/site/time.eith. Types and signatures are exactly what the compiler checks scripts against. Back to all modules.

site/time.eith
// site/time: timers. Callbacks run later with a fresh step budget.

pub fn after(ms: i64, run: fn() -> void) -> i64     // once, after at least 100 ms
pub fn every(ms: i64, run: fn() -> void) -> i64     // repeatedly, at least 250 ms apart
pub fn cancel(id: i64) -> void