pub struct Timer(/* private fields */);
Expand description
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§
Source§impl Timer
impl Timer
Sourcepub fn reschedule_ms(&self, ms: u32)
pub fn reschedule_ms(&self, ms: u32)
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.
Sourcepub fn reschedule(&self, dur: Duration)
pub fn reschedule(&self, dur: Duration)
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.
Sourcepub fn reschedule_ticks(&self, ticks: u32)
pub fn reschedule_ticks(&self, ticks: u32)
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.
Sourcepub fn reschedule_at(&self, ticks: u32)
pub fn reschedule_at(&self, ticks: u32)
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§
Auto Trait Implementations§
impl Freeze for Timer
impl !RefUnwindSafe for Timer
impl !Send for Timer
impl !Sync for Timer
impl Unpin for Timer
impl !UnwindSafe for Timer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Source§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f
. Read moreSource§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
Source§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Source§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where
Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>.Source§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where
Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>.