pub struct ManualTimeProvider { /* private fields */ }Expand description
Implementation of TimeProvider that allows manual control of time
This provider allows you to explicitly set the current time for testing time-dependent code without relying on the system clock.
Implementations§
Source§impl ManualTimeProvider
impl ManualTimeProvider
Sourcepub fn new(start_time_millis: TimeMillis) -> Self
pub fn new(start_time_millis: TimeMillis) -> Self
Create a new ManualTimeProvider with a specified starting time
Sourcepub async fn run_all_sleepers_till_done(
&self,
cancellation_token: &CancellationToken,
)
pub async fn run_all_sleepers_till_done( &self, cancellation_token: &CancellationToken, )
Advance time until there are no more registered sleepers.
It jumps time forward to the next wakeup repeatedly, waking all due tasks, and yields to the executor so those tasks can make progress and potentially register more sleeps.
Sourcepub async fn advance_time_until_next_sleeper(&self)
pub async fn advance_time_until_next_sleeper(&self)
Advance time to the earlier of: the next scheduled wake time or the current time plus max_advance_ms
Returns the amount of time (in milliseconds) that was actually advanced and the remaining number of sleeping taks
Trait Implementations§
Source§impl Clone for ManualTimeProvider
impl Clone for ManualTimeProvider
Source§fn clone(&self) -> ManualTimeProvider
fn clone(&self) -> ManualTimeProvider
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for ManualTimeProvider
impl Default for ManualTimeProvider
Source§impl TimeProvider for ManualTimeProvider
impl TimeProvider for ManualTimeProvider
Source§fn current_time_millis(&self) -> TimeMillis
fn current_time_millis(&self) -> TimeMillis
Returns the current time in milliseconds since the UNIX epoch
fn sleep(&self, duration: Duration) -> Pin<Box<dyn Future<Output = ()> + Send>>
fn current_time_str(&self) -> String
Source§fn current_datetime(&self) -> DateTime<Utc>
fn current_datetime(&self) -> DateTime<Utc>
Convert the current time to a
DateTime<Utc>fn sleep_millis( &self, millis: DurationMillis, ) -> Pin<Box<dyn Future<Output = ()> + Send>>
Auto Trait Implementations§
impl Freeze for ManualTimeProvider
impl !RefUnwindSafe for ManualTimeProvider
impl Send for ManualTimeProvider
impl Sync for ManualTimeProvider
impl Unpin for ManualTimeProvider
impl UnsafeUnpin for ManualTimeProvider
impl !UnwindSafe for ManualTimeProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more