pub struct TimerRegistry { /* private fields */ }

Implementations§

source§

impl TimerRegistry

source

pub fn sleep( &self, duration: Duration ) -> impl Future<Output = TimeHandlerGuard> + Send + Sync + 'static

Schedules a timer to expire in “Duration”, once expired, returns a TimeHandlerGuard that must be dropped only once the timer event has been fully processed (all sideeffects finished).

Roughly eqivalent to async pub fn sleep(&self, duration: Duration) -> TimeHandlerGuard.

source

pub fn sleep_until( &self, until: Instant ) -> impl Future<Output = TimeHandlerGuard> + Send + Sync + 'static

Schedules a timer to expire at “Instant”, once expired, returns a TimeHandlerGuard that must be dropped only once the timer event has been fully processed (all sideeffects finished).

Roughly eqivalent to async pub fn sleep_until(&self, until: Instant) -> TimeHandlerGuard.

§Panics

When until was created by a different instance of TimerRegistry.

source

pub fn timeout<F>(&self, timeout: Duration, future: F) -> Timeout<F>
where F: Future,

Combines a future with a sleep timer. If the future finishes before the timer has expired, returns the futures output. Otherwise returns Elapsed which contains a TimeHandlerGuard that must be dropped once the timeout has been fully processed (all sideeffects finished).

Roughly equivalent to async pub fn timeout<F: Future>(&self, timeout: Duration, future: F) -> Result<F::Output, Elapsed>

source

pub fn timeout_at<F>(&self, at: Instant, future: F) -> Timeout<F>
where F: Future,

Combines a future with a sleep_until timer. If the future finishes before the timer has expired, returns the futures output. Otherwise returns Elapsed which contains a TimeHandlerGuard that must be dropped once the timeout has been fully processed (all sideeffects finished).

Roughly equivalent to async pub fn timeout_at<F: Future>(&self, at: Instant, future: F) -> Result<F::Output, Elapsed>

§Panics

When at was created by a different instance of TimerRegistry.

source

pub fn interval(self: &Arc<Self>, period: Duration) -> Interval

source

pub fn interval_at( self: &Arc<Self>, start: Instant, period: Duration ) -> Interval

source

pub async fn advance_time(&self, by_duration: Duration)

Advances test time by the given duration. Starts all scheduled timers that have expired at the new (advanced) point in time in the following order:

  1. By time they are scheduled to run at
  2. By the order they were scheduled

If no timer has been scheduled yet, waits until one is. Returns only once all started timers have finished processing.

source

pub fn now(&self) -> Instant

Current test time, increases on every call to [advance_time].

Trait Implementations§

source§

impl Debug for TimerRegistry

source§

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

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

impl Default for TimerRegistry

source§

fn default() -> Self

Returns the “default value” for a type. 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<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<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.