pub struct WaitTimer(/* private fields */);nano-alloc only.Expand description
A high-precision asynchronous timer based on hardware ticks.
WaitTimer leverages the CPU’s Time Stamp Counter (TSC) to provide non-blocking
delays ranging from picoseconds to years. It implements the Future trait,
allowing the executor to suspend tasks until the specified hardware deadline is reached.
§Precision and Accuracy
The timer relies on the calibrated frequency stored in FREQ. Accuracy is
determined by the sampling quality during init_clock_freq().
§Examples
Using the builder-style methods:
async fn delay_example() {
// Create a timer for 500 milliseconds
WaitTimer::from_ms(500).await;
}Using the _WaitTimer extension trait for a more expressive DSL:
use uefi_async::nano_alloc::time::{WaitTimer, _WaitTimer};
async fn blink_led_task() {
loop {
// Highly readable duration syntax
1.s().await; // Wait 1 second
500.ms().await; // Wait 500 milliseconds
20.fps().await; // Wait for 1 frame duration at 20 FPS (50ms)
// Precise sub-microsecond timing
10.us().await; // 10 microseconds
80.ps().await; // 80 picoseconds (Note: Dependent on CPU Ghz)
// Long-term scheduling
2.hour().await;
1.day().await;
}
}Implementations§
Source§impl WaitTimer
impl WaitTimer
Sourcepub fn until(deadline: u64) -> Self
pub fn until(deadline: u64) -> Self
Constructs a timer that expires at an absolute hardware tick count.
Sourcepub fn after(ticks_to_wait: u64) -> Self
pub fn after(ticks_to_wait: u64) -> Self
Constructs a timer that expires after a relative number of ticks from now.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Checks if the current hardware tick has reached or exceeded the deadline.
This uses a direct comparison, assuming the timer is polled frequently enough to handle 64-bit tick overflows (which take centuries on modern CPUs).