Skip to content

module

timers

Time for templates' timers (every, after, every frame).

The browser installs a Host that uses setTimeout and requestAnimationFrame. Without one, timers wait on a virtual clock that only moves when something calls advance: prerendering never does, so no timer runs at build time, and tests move time on as they need.

Structs

  • Host

    What runs timers.

Functions

advance

pub fn advance(ms: f64)

Move the virtual clock on by ms, a frame (16 ms) at a time, running frames and the timers that come due. Does nothing to a browser's clock.

host

pub fn host() -> Host

The host: the one set, or the virtual clock.

note_use

pub fn note_use()

Note that the page being rendered starts timers (or listens for window events), so it needs the runtime in the browser.

pending

pub fn pending() -> usize

How many timers and frame callbacks the virtual clock is holding.

set_host

pub fn set_host(host: Host)

Set the host (the browser does, when the app starts).

take_use

pub fn take_use() -> bool

Whether note_use was called since the last call (one page's worth).

Constants

FRAME_MS

pub const FRAME_MS: f64 = 16.0;

How often a virtual frame comes: about 60 a second.

Type aliases

Cancel

pub type Cancel = Box<dyn FnOnce()>;

Stops a timer.

EachFrame

pub type EachFrame = Box<dyn FnMut(f64) -> bool>;

Runs every frame with the time (ms); returns whether to keep going.

Once

pub type Once = Box<dyn FnOnce()>;

Runs once.