1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Time abstraction for es-entity with support for real and manual time.
//!
//! This crate provides a unified interface for time operations that works
//! identically whether using real time or manual time for testing.
//!
//! # Overview
//!
//! The main type is [`ClockHandle`], a cheap-to-clone handle that provides:
//! - `now()` - Get current time (synchronous, fast)
//! - `sleep(duration)` - Sleep for a duration
//! - `timeout(duration, future)` - Timeout a future
//!
//! For manual clocks, a [`ClockController`] is also provided for controlling time.
//!
//! # Clock Types
//!
//! - **Realtime**: Uses system clock and tokio timers
//! - **Manual**: Time only advances via explicit `advance()` calls
//!
//! # Example
//!
//! ```rust
//! use es_entity::clock::ClockHandle;
//! use std::time::Duration;
//!
//! // Production: use real time
//! let clock = ClockHandle::realtime();
//!
//! // Testing: use manual clock
//! let (clock, ctrl) = ClockHandle::manual();
//!
//! // Same interface regardless of clock type
//! let now = clock.now();
//! ```
//!
//! # Deterministic Testing
//!
//! In manual mode, time only advances when you call `advance()`.
//! Wake events are processed in chronological order, so tasks always see
//! the correct time when they wake:
//!
//! ```rust
//! use es_entity::clock::ClockHandle;
//! use std::time::Duration;
//!
//! # async fn example() {
//! let (clock, ctrl) = ClockHandle::manual();
//!
//! let clock2 = clock.clone();
//! tokio::spawn(async move {
//! clock2.sleep(Duration::from_secs(3600)).await; // 1 hour
//! // When this wakes, clock2.now() == start + 1 hour
//! // (even if advance() jumped further)
//! });
//!
//! // Advance 1 day - but the task wakes at exactly +1 hour
//! ctrl.advance(Duration::from_secs(86400)).await;
//! # }
//! ```
// Re-export public API
pub use ClockController;
pub use Clock;
pub use ;
pub use ;