Expand description
Wall-clock and frame-based timers without an async runtime.
Schedule a callback for an Instant or a frame count; the platform
wakes the event loop exactly then via ReposeRuntime::next_wakeup_deadline
(ControlFlow::WaitUntil). No executor, no threads, no per-frame cost
when idle.
Compose parallels (approximate):
| Compose | Here |
|---|---|
delay(d) half of LaunchedEffect | delay (unscoped; hold handle) |
LaunchedEffect without keys | scoped_delay (unmount only) |
| fixed-rate repetition | interval (drift-free) |
| run-after-deadline | timeout (delay alias) |
flow debounce (trailing edge) | Debouncer / debounced_signal |
| sequencing over redraws | delay_frames |
Caveats vs coroutines: handles and flags suppress only pending firings.
There is no counterpart for cancelling running work (LaunchedEffect
key-change/leave, withTimeout aborting in-flight work, collectLatest):
a firing callback runs to completion, timeout is not withTimeout, and
delay_frames counts redraw polls (no vsync timestamp, refresh-rate
dependent) rather than subscribing to frames.
Rules of thumb: wall-clock waiting goes through delay/interval;
sequencing after animations or redraws through delay_frames; reactive
signal shaping through debounced_signal.
Structs§
- Debouncer
- Trailing-edge debouncer: each call reschedules the single pending firing. Cloneable (shared slot); dropping all clones cancels it.
- Throttler
- Leading-edge throttler with one coalesced trailing firing per period.
- Timer
Handle - Owner of a scheduled timer. Dropping cancels it (no-op if already fired).
Functions§
- delay
- Run
cbonce afterduration. Returns a handle; dropping it cancels. - delay_
frames - Run
cbonce afterframesredraws have been polled. Counts polls, not vsync frames: no timestamp, refresh-rate dependent. While frame entries are pendingpollkeeps requesting frames. A0count fires on the next poll. - frame_
count - Current redraw count (advanced by
poll). Basis fordelay_frames. - interval
- Run
cbeveryperiod, drift-free (next fire = last scheduled fire +period, so slow frames skip beats instead of bunching). Dropping the handle stops the timer. Periods below 1ms are clamped to 1ms. - interval_
n - Like
interval, but stops on its own aftertimesfirings. A0count schedules nothing and returns a disarmed handle. - next_
deadline - Earliest wall-clock deadline, if any. Fed into
ReposeRuntime::next_wakeup_deadlineso the platform sleeps until a timer is due. - poll
- Advance the frame counter and fire due timers. Called once per redraw
(from
ReposeRuntime::tick_overlays). Reentrant calls, e.g. from inside a timer callback, are ignored: the outer pass already collected the due timers, so a nested pass would fire them twice. - scoped_
delay delaytied to the current composition scope: if the scope disposes before the deadline, the callback is suppressed. Schedules once per mount; usescoped_delay_with_keyto restart on change.- scoped_
delay_ with_ key - Keyed
scoped_delay: reschedules whenkeychanges (cancelling the previous generation via its flag) and suppresses on unmount. Must be called inside composition; outside a scope it degrades todelay. - timeout
- Run
cbonce afterduration. Adelayalias naming the run-after-deadline intent. This is notwithTimeout: it cannot abort in-flight work, it only startscbonce the duration elapses.