Skip to main content

VirtualClock

Struct VirtualClock 

Source
pub struct VirtualClock { /* private fields */ }
Expand description

Virtual wall, elapsed and scheduler clocks. Scheduler time is what timers are registered against; it moves only when a history delivers timers, so a silent shift never fires a deliberately held timer.

Implementations§

Source§

impl VirtualClock

Source

pub fn new(wall_ms: i64) -> Arc<Self> ⓘ

A clock at wall_ms epoch milliseconds with zero elapsed and scheduler time.

Source

pub fn shift(&self, delta_ms: i64, wall_only: bool)

Move wall (and unless wall_only, elapsed) time without delivering timers.

Source

pub fn shift_ns(&self, delta_ns: i128, wall_only: bool)

shift in nanoseconds; elapsed time saturates at zero.

Source

pub fn pending_timers(&self) -> usize

Timers registered and neither fired nor dropped.

Source§

impl VirtualClock

Source

pub fn sleep(&self, duration: Duration) -> BoxFuture<'static, ()>

Register a timer against scheduler time.

Trait Implementations§

Source§

impl Clock for VirtualClock

Source§

fn wall_ms(&self) -> i64

Epoch milliseconds from the application wall clock.
Source§

fn elapsed(&self) -> Duration

Monotonic elapsed time since this clock’s origin, with native precision.
Source§

fn elapsed_ms(&self) -> i64

Whole-millisecond elapsed reading used by process-local storage. Read more
Source§

impl Debug for VirtualClock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.