Struct PausableClock

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

Source of time information that can be paused and resumed. At its heart it is a reference instant in real time, a record of elapsed time, and an atomic state stored in a u64

Implementations§

Source§

impl PausableClock

Source

pub fn new(elapsed_time: Duration, paused: bool) -> PausableClock

Create a new pausable clock with the given pause state and the given elapsed time

Source

pub fn now(&self) -> PausableInstant

Get the current time according to the clock

Source

pub fn pause(&self) -> bool

Pause the pausable clock. This function will set the pause state to pausing, then to paused. This ensures that no times will be read in the time between when now is read and when the pause state is set that is greater than the paused time.

Note. This method will block synchronously if there are unpausable tasks being run.

True will be returned for a successful pause (meaning the clock wasn’t already paused), and false will be returned if the clock was paused when this method was called.

Source

pub fn resume(&self) -> bool

Resume the pausable clock. This function will set the pause state to resuming, then to resumed.

Note. This method will block synchronously if there are unresumable tasks being run.

True will be returned for a successful resume (meaning the clock wasn’t already resumed), and false will be returned if the clock was resumed when this method was called.

Source

pub fn is_paused(&self) -> bool

Check to see if the clock is paused using relaxed atomic ordering

Source

pub fn is_pausing(&self) -> bool

Check to see if the clock is pausing using relaxed atomic ordering. Note that a clock that is paused will not be pausing

Source

pub fn is_paused_or_pausing(&self) -> bool

Check to see if the clock is paused or pausing using relaxed atomic ordering

Source

pub fn wait_for_resume(&self)

Block the current thread until the clock resumes. If the clock is not paused when this method is called, the method will return without blocking

Source

pub fn wait_for_pause(&self)

Block the current thread until the clock pauses. If the clock is paused when this method is called, the method will return without blocking

Source

pub fn run_unpausable<F, T>(&self, action: F) -> T
where F: FnOnce() -> T,

This method provides a way to run in coordination with the pause functionality of the clock. A task run with this method will prevent the clock from being paused, and will not be run while the clock is paused

Source

pub fn run_if_resumed<F, T>(&self, action: F) -> Option<T>
where F: FnOnce() -> T,

This method provides a way to run in coordination with the pause functionality of the clock. A task run with this method will prevent the clock from being paused, but will not be run if the clock is paused. The turn will contain the result of evaluation of the task if the task is run, and will be None if the task was not run (meaning the clock was paused)

Source

pub fn run_unresumable<F, T>(&self, action: F) -> T
where F: FnOnce() -> T,

This method provides a way to run in coordination with the resume functionality of the clock. A task run with this method will prevent the clock from being resumed, and will not be run while the clock is resumed

Source

pub fn run_if_paused<F, T>(&self, action: F) -> Option<T>
where F: FnOnce() -> T,

This method provides a way to run in coordination with the resume functionality of the clock. A task run with this method will prevent the clock from being resumed, but will not be run if the clock is not already paused. The turn will contain the result of evaluation of the task if the task is run, and will be None if the task was not run (meaning the clock was running)

Source

pub fn is_paused_ordered(&self, ordering: Ordering) -> bool

Check to see if the clock is paused using the given atomic ordering

Source

pub fn is_pausing_ordered(&self, ordering: Ordering) -> bool

Check to see if the clock is pausing using the given atomic ordering. Note that a clock that is paused will not be pausing

Source

pub fn is_paused_or_pausing_ordered(&self, ordering: Ordering) -> bool

Check to see if the clock is paused or pausing using the given atomic ordering

Source

pub fn is_resumed_or_resuming_ordered(&self, ordering: Ordering) -> bool

Check to see if the clock is resumed or resuming using the given atomic ordering

Trait Implementations§

Source§

impl Debug for PausableClock

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for PausableClock

The default pausable clock is one that is (more or less) identical to real time: Not paused and starting with zero starting offset

Source§

fn default() -> Self

Returns the “default value” for a type. 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, 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.