[][src]Struct ndless_async::timer::Timer

pub struct Timer(_);

Waits for a specific time.

Use TimerListener::sleep, TimerListener::sleep_ms, TimerListener::sleep_ticks, or TimerListener::sleep_until to create a Timer.

The timer can be rescheduled with the reschedule series of functions. If the original time period has already passed, it will re-trigger after the new time period.

The calculator is automatically put to sleep until the next timer to conserve power.

use ndless_async::task::{block_on, AsyncListeners};

let listeners = AsyncListeners::new();
block_on(&listeners, async {
    let late_by = listeners.timer().sleep_ms(1000).await;
    println!("Done sleeping! This event was expected {:?} ago", late_by);
});

Implementations

impl Timer[src]

pub fn at_tick(&self) -> u32[src]

Get the tick that this timer should fire at

pub fn reschedule_ms(&self, ms: u32)[src]

Reschedules this timer for the specified number of milliseconds. Problems will occur when sleeping for more than 2^31/32768 seconds, which is about 18 hours.

If this timer has already triggered, it will trigger again after the specified delay.

pub fn reschedule(&self, dur: Duration)[src]

Reschedules this timer for the specified Duration. Problems will occur when sleeping for more than 2^31/32768 seconds, which is about 18 hours.

If this timer has already triggered, it will trigger again after the specified delay.

This function has a resolution of 30 μs.

pub fn reschedule_ticks(&self, ticks: u32)[src]

Reschedules this timer for the specified number of ticks. Problems will occur when sleeping for more than 2^31 ticks, which is about 18 hours.

If this timer has already triggered, it will trigger again after the specified delay.

pub fn reschedule_at(&self, ticks: u32)[src]

Reschedules this timer until the current number of ticks is equal to the parameter. Problems will occur when sleeping for more than 2^31 ticks in the future, which is about 18 hours.

If this timer has already triggered, it will trigger again after the specified delay.

Trait Implementations

impl Future for Timer[src]

type Output = Duration

The difference between now and when this event should have occurred.

Auto Trait Implementations

impl !Send for Timer

impl !Sync for Timer

impl Unpin for Timer

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> FutureExt for T where
    T: Future + ?Sized
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.