WaitTimer

Struct WaitTimer 

Source
pub struct WaitTimer(/* private fields */);
Available on crate feature 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

Source

pub fn until(deadline: u64) -> Self

Constructs a timer that expires at an absolute hardware tick count.

Source

pub fn after(ticks_to_wait: u64) -> Self

Constructs a timer that expires after a relative number of ticks from now.

Source

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).

Source

pub fn from_year(y: u64) -> Self

Source

pub fn from_month(m: u64) -> Self

Source

pub fn from_week(w: u64) -> Self

Source

pub fn from_day(d: u64) -> Self

Source

pub fn from_hour(h: u64) -> Self

Source

pub fn from_min(min: u64) -> Self

Source

pub fn from_s(hz: u64) -> Self

Source

pub fn from_ms(ms: u64) -> Self

Source

pub fn from_us(us: u64) -> Self

Source

pub fn from_ns(ns: u64) -> Self

Source

pub fn from_ps(ps: u64) -> Self

Source

pub fn from_fps(fps: u64) -> Self

Trait Implementations§

Source§

impl Debug for WaitTimer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Future for WaitTimer

Source§

type Output = ()

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<F> FutureExt for F
where F: Future + ?Sized,

Source§

fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output>
where Self: Unpin,

A convenience for calling Future::poll() on !Unpin types.
Source§

fn or<F>(self, other: F) -> Or<Self, F>
where Self: Sized, F: Future<Output = Self::Output>,

Returns the result of self or other future, preferring self if both are ready. Read more
Source§

fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
where Self: Sized + Send + 'a,

Available on crate feature alloc only.
Boxes the future and changes its type to dyn Future + Send + 'a. Read more
Source§

fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>
where Self: Sized + 'a,

Available on crate feature alloc only.
Boxes the future and changes its type to dyn Future + 'a. Read more
Source§

impl<F1> FutureExt for F1
where F1: Future,

Source§

fn join<F2>(self, other: F2) -> Join2<F1, <F2 as IntoFuture>::IntoFuture>
where F1: Future, F2: IntoFuture,

Wait for both futures to complete.
Source§

fn race<T, S2>(self, other: S2) -> Race2<T, F1, <S2 as IntoFuture>::IntoFuture>
where F1: Future<Output = T>, S2: IntoFuture<Output = T>,

Wait for the first future to complete.
Source§

fn wait_until<D>( self, deadline: D, ) -> WaitUntil<Self, <D as IntoFuture>::IntoFuture>
where Self: Sized, D: IntoFuture,

Delay resolving the future until the given deadline. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<F> _Timeout<'_> for F
where F: Future,

Source§

fn timeout(self, duration_ticks: u64) -> Timeout<'bemly_, Self::Output>
where Self: 'bemly_,

Available on crate feature nano-alloc only.
Wraps the future in a Timeout with the specified duration in hardware ticks.
Source§

impl<T> SafeFuture for T
where T: Future<Output = ()> + 'static + Send + Sync,