Struct diem_time_service::mock::MockTimeService
source · pub struct MockTimeService { /* private fields */ }
Expand description
A TimeService
that simulates time and allows for
fine-grained control over advancing time and waking up sleeping tasks.
Auto Advance
MockTimeService
has the option to auto advance time when new Sleep
s are
crated. When we’re auto advancing, new Sleep
s are immediately resolved and
the simulation time is advanced to the wait deadline. New Sleep
s whose deadlines
are after the auto advance deadline will be pending and must be manually
woken by the MockTimeService::advance_{..}
methods.
Implementations§
source§impl MockTimeService
impl MockTimeService
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new MockTimeService
with no auto advance. Time will only advance
by manually calling the MockTimeService::advance_{..}
methods.
sourcepub fn new_auto_advance() -> Self
pub fn new_auto_advance() -> Self
Create a new MockTimeService
that will auto advance forever.
sourcepub fn new_auto_advance_for(deadline: Duration) -> Self
pub fn new_auto_advance_for(deadline: Duration) -> Self
Create a new MockTimeService
that will auto advance until the simulation
time passes deadline
.
sourcepub fn num_waiters(&self) -> usize
pub fn num_waiters(&self) -> usize
Return the number of pending Sleep
waiters.
sourcepub fn advance_next(&self) -> Option<Duration>
pub fn advance_next(&self) -> Option<Duration>
Advance time to the next pending waiter, wake it up, and return the wake
time, or None
if there are no waiters.
sourcepub fn advance(&self, duration: Duration) -> usize
pub fn advance(&self, duration: Duration) -> usize
Advance time by duration
and wake any pending waiters whose sleep has
expired. Return the number of waiters that we woke up.
sourcepub fn advance_secs(&self, duration: u64) -> usize
pub fn advance_secs(&self, duration: u64) -> usize
Advance time by duration
seconds. See advance
.
sourcepub fn advance_ms(&self, duration: u64) -> usize
pub fn advance_ms(&self, duration: u64) -> usize
Advance time by duration
milliseconds. See advance
.
sourcepub async fn advance_next_async(&self) -> Option<Duration>
pub async fn advance_next_async(&self) -> Option<Duration>
Advance time to the next pending waiter, wake it up, and return the wake
time, or None
if there are no waiters.
Yields to the executor to run any freshly awoken tasks (which might also
create more Sleep
futures).
sourcepub async fn advance_async(&self, duration: Duration) -> usize
pub async fn advance_async(&self, duration: Duration) -> usize
Advance time by duration
and wake any pending waiters whose sleep has
expired. Return the number of waiters that we woke up.
Yields to the executor to run any freshly awoken tasks (which might also
create more Sleep
futures).
sourcepub async fn advance_secs_async(&self, duration: u64) -> usize
pub async fn advance_secs_async(&self, duration: u64) -> usize
Advance time by duration
seconds.
See advance_async
.
sourcepub async fn advance_ms_async(&self, duration: u64) -> usize
pub async fn advance_ms_async(&self, duration: u64) -> usize
Advance time by duration
milliseconds.
See advance_async
.
Trait Implementations§
source§impl Clone for MockTimeService
impl Clone for MockTimeService
source§fn clone(&self) -> MockTimeService
fn clone(&self) -> MockTimeService
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for MockTimeService
impl Debug for MockTimeService
source§impl From<MockTimeService> for TimeService
impl From<MockTimeService> for TimeService
source§fn from(v: MockTimeService) -> TimeService
fn from(v: MockTimeService) -> TimeService
source§impl TimeServiceTrait for MockTimeService
impl TimeServiceTrait for MockTimeService
source§fn now(&self) -> Instant
fn now(&self) -> Instant
Instant
s, i.e., this is a monotonic
relative time whereas now_unix_time
is a
non-monotonic absolute time. Read moresource§fn sleep_blocking(&self, duration: Duration)
fn sleep_blocking(&self, duration: Duration)
duration
time has passed.