1use std::sync::Arc;
2use std::sync::atomic::{AtomicBool, Ordering};
3
4#[derive(Debug, Default, Clone)]
7pub struct Liveness(Arc<AtomicBool>);
8
9impl Liveness {
10 pub fn new() -> Self {
11 Self(Arc::new(AtomicBool::new(false)))
12 }
13
14 pub fn is_alive(&self) -> bool {
15 self.0.load(Ordering::Acquire)
16 }
17
18 pub fn born(&self) {
19 self.0.store(true, Ordering::Release);
20 }
21
22 pub fn dead(&self) {
23 self.0.store(false, Ordering::Release);
24 }
25}
26
27#[derive(Debug, Default, Clone)]
29pub struct Cancel(Arc<AtomicBool>);
30
31impl Cancel {
32 pub fn new() -> Self {
33 Self(Arc::new(AtomicBool::new(false)))
34 }
35
36 pub fn is_canceled(&self) -> bool {
37 self.0.load(Ordering::Acquire)
38 }
39
40 pub fn cancel(&self) {
41 self.0.store(true, Ordering::Release);
42 }
43}