Skip to main content

Module time

Module time 

Source
Expand description

Static timing: const-generic durations and async sleep futures.

Sleep registers its deadline with crate::timer on first poll and then returns Pending without re-arming its own waker โ€” the platform timer ISR wakes it when the deadline passes. This means a sleeping task does not busy-poll: between ticks the executor has nothing ready and genuinely enters port::arch::idle() (WFI), which is what makes tickless idle actually save power instead of spinning.

โ“˜
use rivet::time::Sleep;

#[rivet::task(priority = 0)]
async fn blink() {
    loop {
        toggle_led();
        Sleep::<500_000>::new().await; // 500ms
    }
}

Structsยง

Duration
A duration in microseconds, known at compile time.
Sleep
A future that resolves after a compile-time-known duration has elapsed.