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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// SPDX-FileCopyrightText: Copyright (c) Siemens 2026 contributed by Christoph Kuhmuench christoph.kuhmuench@gmail.com
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use RefCell;
use Future;
use Pin;
use Rc;
use ;
/// The sending half of a manual event. Call [`fire`](EventTrigger::fire) to
/// wake all processes currently waiting on the paired [`EventAwaitable`], and
/// to make any *future* awaits on that same awaitable resolve immediately.
///
/// **Dropping a trigger without firing it strands its waiters.** If an
/// `EventTrigger` is dropped without `fire()` being called, the event never
/// fires: any process currently awaiting the paired `EventAwaitable` — and any
/// that awaits it later — will suspend forever (until the run ends and
/// [`SimEnv`](crate::SimEnv)'s `Drop` reclaims the suspended processes). This is
/// a normal discrete-event outcome (a signal that simply never arrives), not a
/// panic; if a process must not block indefinitely, race the awaitable against a
/// [`timeout`](crate::EnvHandle::timeout) via [`any_of!`](crate::any_of).
///
/// One trigger, many waiters — including one that only starts waiting *after*
/// the fire (the latch makes it resolve immediately):
///
/// ```
/// use simu::SimEnv;
///
/// let mut env = SimEnv::with_seed(0);
/// let (trigger, ready) = env.event();
///
/// // Fires at t = 2.
/// let h = env.handle();
/// env.spawn(async move {
/// h.timeout(2.0).await;
/// trigger.fire(); // consumes the trigger — an event fires at most once
/// });
///
/// // Suspends now, woken at t = 2.
/// let r = ready.clone(); // Clone = same underlying event
/// let h1 = env.handle();
/// env.spawn(async move {
/// r.await;
/// assert_eq!(h1.now(), 2.0);
/// });
///
/// // Starts waiting at t = 3 — after the fire — and resolves immediately.
/// let h2 = env.handle();
/// env.spawn(async move {
/// h2.timeout(3.0).await;
/// ready.await; // already fired: no suspension
/// assert_eq!(h2.now(), 3.0);
/// });
///
/// env.run();
/// ```
/// The receiving half of a manual event.
///
/// Implements `Future<Output = ()>`. If the paired [`EventTrigger`] has
/// already fired, polling returns `Ready` immediately. Otherwise the calling
/// process is suspended and woken when [`EventTrigger::fire`] is called.
///
/// `EventAwaitable` is `Clone`: every clone shares the same underlying event,
/// so multiple processes can await the same trigger.
/// Create a paired `(EventTrigger, EventAwaitable)`.
pub