pub struct SimClock { /* private fields */ }Expand description
A simulated clock for deterministic testing.
TigerStyle:
- Time only moves forward
- All time operations are explicit
- No reliance on system time
- Supports async sleep with notify for coordination
Thread-safe via Arc
Implementations§
Source§impl SimClock
impl SimClock
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new clock starting at time zero.
§Example
use umi_memory::dst::SimClock;
let clock = SimClock::new();
assert_eq!(clock.now_ms(), 0);Sourcepub fn at_ms(start_ms: u64) -> Self
pub fn at_ms(start_ms: u64) -> Self
Create a clock starting at the given millisecond timestamp.
Sourcepub fn at_datetime(dt: DateTime<Utc>) -> Self
pub fn at_datetime(dt: DateTime<Utc>) -> Self
Create a clock starting at the given DateTime.
Sourcepub fn from_epoch() -> Self
pub fn from_epoch() -> Self
Create a clock starting at Unix epoch (1970-01-01).
Sourcepub fn advance_ms(&self, ms: u64) -> u64
pub fn advance_ms(&self, ms: u64) -> u64
Sourcepub fn advance_secs(&self, secs: f64) -> u64
pub fn advance_secs(&self, secs: f64) -> u64
Sourcepub fn elapsed_since(&self, since: u64) -> u64
pub fn elapsed_since(&self, since: u64) -> u64
Sourcepub fn has_elapsed(&self, since: u64, duration_ms: u64) -> bool
pub fn has_elapsed(&self, since: u64, duration_ms: u64) -> bool
Check if a given duration has elapsed since a timestamp.
Sourcepub fn is_past_ms(&self, deadline_ms: u64) -> bool
pub fn is_past_ms(&self, deadline_ms: u64) -> bool
Check if a deadline (in ms) has passed.
Sourcepub fn is_past(&self, deadline: DateTime<Utc>) -> bool
pub fn is_past(&self, deadline: DateTime<Utc>) -> bool
Check if a DateTime deadline has passed.
Sourcepub async fn sleep_ms(&self, duration_ms: u64)
pub async fn sleep_ms(&self, duration_ms: u64)
Sleep until the specified duration has passed.
In simulation mode, this yields and waits for time to be advanced. Returns when current_time >= start_time + duration_ms.
Sourcepub async fn sleep_until_ms(&self, deadline_ms: u64)
pub async fn sleep_until_ms(&self, deadline_ms: u64)
Sleep until a specific deadline.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SimClock
impl RefUnwindSafe for SimClock
impl Send for SimClock
impl Sync for SimClock
impl Unpin for SimClock
impl UnwindSafe for SimClock
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