ralph_workflow/runtime/clock.rs
1//! Clock and time utilities in the runtime boundary.
2//!
3//! This module provides time-related capabilities that domain code
4//! can use through trait abstraction.
5
6use std::time::{Duration, Instant};
7
8/// Trait for time operations, allowing testability.
9pub trait Clock: Send + Sync {
10 /// Get the current instant.
11 fn now(&self) -> Instant;
12
13 /// Get a duration since the given instant.
14 fn elapsed(&self, start: Instant) -> Duration {
15 self.now().duration_since(start)
16 }
17}
18
19/// Real clock implementation using system time.
20pub struct RealClock;
21
22impl Clock for RealClock {
23 fn now(&self) -> Instant {
24 Instant::now()
25 }
26}