Pausable Clock

This crate provides a clock that can be paused ... (duh?). The provided struct PausableClock allows you to get the current time in a way that respects the atomic state and history of the clock. Put more simply, a pausable clock's elapsed time increases at the same as real time but only when the clock is resumed.

Features

Example

```rust use pausable_clock::PausableClock; use std::sync::Arc; use std::thread; use std::time::{Duration, Instant};

let clock = Arc::new(PausableClock::default());

// With the default parameters, there should be no difference // between the real time and the clock's time assert!(Instant::from(clock.now()).elapsed().as_millis() == 0);

// Pause the clock right after creation clock.pause();

// Clone the arc of the clock to pass to a new thread let clock_clone = clock.clone();

let t = thread::spawn(move || { // In the new thread, just wait for resume clockclone.waitfor_resume(); });

// Sleep for a sec, then resume the clock thread::sleep(Duration::from_secs(1)); clock.resume();

// Wait for the spawned thread to unblock t.join().unwrap();

// After being paused for a second, the clock is now a second behind // (with a small error margin here because sleep is not super accurate) assert!((Instant::from(clock.now()).elapsed().assecsf64() - 1.).abs() < 0.005); ```

Caveats