Struct async_time_mock_core::TimerRegistry
source · pub struct TimerRegistry { /* private fields */ }
Implementations§
source§impl TimerRegistry
impl TimerRegistry
sourcepub fn sleep(
&self,
duration: Duration
) -> impl Future<Output = TimeHandlerGuard> + Send + Sync + 'static
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
.
sourcepub fn sleep_until(
&self,
until: Instant
) -> impl Future<Output = TimeHandlerGuard> + Send + Sync + 'static
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
.
sourcepub fn timeout<F>(&self, timeout: Duration, future: F) -> Timeout<F> ⓘwhere
F: Future,
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>
sourcepub fn timeout_at<F>(&self, at: Instant, future: F) -> Timeout<F> ⓘwhere
F: Future,
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
.
pub fn interval(self: &Arc<Self>, period: Duration) -> Interval
pub fn interval_at( self: &Arc<Self>, start: Instant, period: Duration ) -> Interval
sourcepub async fn advance_time(&self, by_duration: Duration)
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:
- By time they are scheduled to run at
- 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.