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
78
79
//! Time primitives: sleep, timeout, and interval operations.
//!
//! This module provides core time-based operations for async programming:
//! - [`Sleep`]: A future that completes after a deadline
//! - [`TimeoutFuture`]: A wrapper that adds a timeout to any future
//! - [`Interval`]: A repeating timer that yields at a fixed period
//!
//! # Virtual vs Wall Time
//!
//! These primitives work with both production (wall clock) time and
//! virtual time in the lab runtime. The time source is determined by
//! the runtime context.
//!
//! # Cancel Safety
//!
//! All time primitives are cancel-safe:
//! - `Sleep`: Can be dropped and recreated without side effects
//! - `TimeoutFuture`: The inner future may have side effects on cancellation
//! - `Interval`: Next tick proceeds from where it was interrupted
//!
//! # Example
//!
//! <!-- core-api-doctest: time-primitives -->
//! ```
//! use asupersync::{Cx, main};
//! use asupersync::time::{interval, sleep, timeout};
//! use asupersync::types::Time;
//! use std::future::ready;
//! use std::time::Duration;
//!
//! #[main]
//! async fn main(cx: &Cx) {
//! cx.checkpoint().expect("example starts active");
//! let now = Time::from_secs(10);
//!
//! let sleeper = sleep(now, Duration::from_millis(100));
//! assert_eq!(sleeper.deadline(), Time::from_nanos(10_100_000_000));
//!
//! let value = timeout(now, Duration::from_secs(5), ready(42_u8))
//! .await
//! .expect("ready future beats its timeout");
//! assert_eq!(value, 42);
//! let elapsed = timeout(now, Duration::from_secs(5), ready(()));
//! assert!(elapsed.is_elapsed(Time::from_secs(15)));
//!
//! let mut ticker = interval(now, Duration::from_millis(100));
//! assert_eq!(ticker.tick(now), now);
//! assert_eq!(ticker.tick(Time::from_nanos(10_100_000_000)), Time::from_nanos(10_100_000_000));
//! }
//! ```
pub use ;
pub use ;
pub use ;
pub use Elapsed;
pub use ;
pub use ;
pub use ;
pub use format_unix_nanos_rfc3339;
pub use ;