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
use ;
use Notify;
/// An interrupt flag with notification capabilities
///
/// The `Interrupt` struct provides a thread-safe way to signal cancellation
/// across async tasks. When triggered, it notifies all waiting tasks to terminate
/// their operations gracefully.
///
/// # Examples
///
/// ```rust
/// use std::time::Duration;
/// use tokio::time::timeout;
///
/// use mahler::sync::Interrupt;
///
/// #[tokio::main]
/// async fn main() {
/// let interrupt = Interrupt::new();
/// let interrupt_clone = interrupt.clone();
///
/// // Spawn a task that will be interrupted
/// let handle = tokio::spawn(async move {
/// interrupt_clone.wait().await;
/// println!("Task was interrupted!");
/// });
///
/// // Trigger the interrupt after a delay
/// tokio::spawn(async move {
/// tokio::time::sleep(Duration::from_millis(100)).await;
/// interrupt.trigger();
/// });
///
/// handle.await.unwrap();
/// }
/// ```