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
impl PausableClock
Sourcepub fn new(elapsed_time: Duration, paused: bool) -> PausableClock
pub fn new(elapsed_time: Duration, paused: bool) -> PausableClock
Create a new pausable clock with the given pause state and the given elapsed time
Sourcepub fn now(&self) -> PausableInstant
pub fn now(&self) -> PausableInstant
Get the current time according to the clock
Sourcepub fn pause(&self) -> bool
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.
Sourcepub fn resume(&self) -> bool
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.
Sourcepub fn is_paused(&self) -> bool
pub fn is_paused(&self) -> bool
Check to see if the clock is paused using relaxed atomic ordering
Sourcepub fn is_pausing(&self) -> bool
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
Sourcepub fn is_paused_or_pausing(&self) -> bool
pub fn is_paused_or_pausing(&self) -> bool
Check to see if the clock is paused or pausing using relaxed atomic ordering
Sourcepub fn wait_for_resume(&self)
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
Sourcepub fn wait_for_pause(&self)
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
Sourcepub fn run_unpausable<F, T>(&self, action: F) -> Twhere
F: FnOnce() -> T,
pub fn run_unpausable<F, T>(&self, action: F) -> Twhere
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
Sourcepub fn run_if_resumed<F, T>(&self, action: F) -> Option<T>where
F: FnOnce() -> T,
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)
Sourcepub fn run_unresumable<F, T>(&self, action: F) -> Twhere
F: FnOnce() -> T,
pub fn run_unresumable<F, T>(&self, action: F) -> Twhere
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
Sourcepub fn run_if_paused<F, T>(&self, action: F) -> Option<T>where
F: FnOnce() -> T,
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)
Sourcepub fn is_paused_ordered(&self, ordering: Ordering) -> bool
pub fn is_paused_ordered(&self, ordering: Ordering) -> bool
Check to see if the clock is paused using the given atomic ordering
Sourcepub fn is_pausing_ordered(&self, ordering: Ordering) -> bool
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
Sourcepub fn is_paused_or_pausing_ordered(&self, ordering: Ordering) -> bool
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
Sourcepub fn is_resumed_or_resuming_ordered(&self, ordering: Ordering) -> bool
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