mofa_runtime/
interrupt.rs1use std::sync::Arc;
2use tokio::sync::Notify;
3
4#[derive(Clone)]
6pub struct AgentInterrupt {
7 pub notify: Arc<Notify>,
8 pub is_interrupted: Arc<std::sync::atomic::AtomicBool>,
9}
10
11impl Default for AgentInterrupt {
12 fn default() -> Self {
13 Self::new()
14 }
15}
16
17impl AgentInterrupt {
18 pub fn new() -> Self {
19 Self {
20 notify: Arc::new(Notify::new()),
21 is_interrupted: Arc::new(std::sync::atomic::AtomicBool::new(false)),
22 }
23 }
24
25 pub fn trigger(&self) {
27 self.is_interrupted
28 .store(true, std::sync::atomic::Ordering::SeqCst);
29 self.notify.notify_one();
30 }
31
32 pub fn check(&self) -> bool {
34 self.is_interrupted
35 .load(std::sync::atomic::Ordering::SeqCst)
36 }
37
38 pub fn reset(&self) {
40 self.is_interrupted
41 .store(false, std::sync::atomic::Ordering::SeqCst);
42 }
43}