pub struct TimerRegistry { /* private fields */ }
Implementations§
Source§impl TimerRegistry
impl TimerRegistry
Sourcepub fn sleep(&self, duration: Duration) -> TimerListener ⓘ
pub fn sleep(&self, duration: Duration) -> TimerListener ⓘ
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) -> TimerListener ⓘ
pub fn sleep_until(&self, until: Instant) -> TimerListener ⓘ
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.
Sourcepub fn system_time(&self) -> SystemTime
pub fn system_time(&self) -> SystemTime
Current test time. Similar to [now
] but simulating system time, not monotonic time.
Increases on every call to [advance_time
].