pub struct MockSleeper { /* private fields */ }Expand description
Relative sleeper driven by a crate::MockTimeline.
MockSleeper is the test implementation of Sleeper. It does not wait
for real wall-clock time. Instead, each sleep captures a deadline on the
backing crate::MockTimeline and completes only after that timeline has
advanced to the deadline.
Cloned sleepers share the same timeline. A sleeper created through
with_timeline can therefore be paired with a
crate::MockClock or future monitor implementation that uses the same
timeline. For most tests, crate::MockTime is the simpler way to create
that shared runtime.
Blocking sleeps register themselves as crate::MockWaiterKind::Sleep so
tests can use
MockTimeline::wait_for_blocked_waiters
before advancing time. With the tokio feature enabled, async sleeps use
the same timeline and waiter registration model.
Implementations§
Source§impl MockSleeper
impl MockSleeper
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a mock sleeper with a fresh timeline.
§Returns
A sleeper backed by a new zero-elapsed timeline.
Sourcepub fn with_timeline(timeline: MockTimeline) -> Self
pub fn with_timeline(timeline: MockTimeline) -> Self
Sourcepub fn timeline(&self) -> MockTimeline
pub fn timeline(&self) -> MockTimeline
Trait Implementations§
Source§impl Clone for MockSleeper
impl Clone for MockSleeper
Source§fn clone(&self) -> MockSleeper
fn clone(&self) -> MockSleeper
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more