pub struct Timer { /* private fields */ }
Expand description
A “timer heap” used to power separately owned instances of Delay
and
Interval
.
This timer is implemented as a priority queued-based heap. Each Timer
contains a few primary methods which which to drive it:
next_wake
indicates how long the ambient system needs to sleep until it invokes further processing on aTimer
advance_to
is what actually fires timers on theTimer
, and should be called essentially every iteration of the event loop, or when the time specified bynext_wake
has elapsed.- The
Future
implementation forTimer
is used to process incoming timer updates and requests. This is used to schedule new timeouts, update existing ones, or delete existing timeouts. TheFuture
implementation will never resolve, but it’ll schedule notifications of when to wake up and process more messages.
Note that if you’re using this crate you probably don’t need to use a
Timer
as there is a global one already available for you run on a helper
thread. If this isn’t desirable, though, then the
TimerHandle::set_fallback
method can be used instead!
Implementations§
Source§impl Timer
impl Timer
Sourcepub fn handle(&self) -> TimerHandle
pub fn handle(&self) -> TimerHandle
Returns a handle to this timer heap, used to create new timeouts.
Sourcepub fn next_event(&self) -> Option<Instant>
pub fn next_event(&self) -> Option<Instant>
Returns the time at which this timer next needs to be invoked with
advance_to
.
Event loops or threads typically want to sleep until the specified instant.
Sourcepub fn advance(&mut self)
pub fn advance(&mut self)
Proces any timers which are supposed to fire at or before the current instant.
This method is equivalent to self.advance_to(Instant::now())
.
Sourcepub fn advance_to(&mut self, now: Instant)
pub fn advance_to(&mut self, now: Instant)
Proces any timers which are supposed to fire before now
specified.
This method should be called on Timer
periodically to advance the
internal state and process any pending timers which need to fire.
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 catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
()
on completion and sends
its output to another future on a separate task. Read moreSource§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
>.