use std::sync::Arc;
use tokio::sync::Notify;
#[derive(Clone)]
pub struct AgentInterrupt {
pub notify: Arc<Notify>,
pub is_interrupted: Arc<std::sync::atomic::AtomicBool>,
}
impl Default for AgentInterrupt {
fn default() -> Self {
Self::new()
}
}
impl AgentInterrupt {
pub fn new() -> Self {
Self {
notify: Arc::new(Notify::new()),
is_interrupted: Arc::new(std::sync::atomic::AtomicBool::new(false)),
}
}
pub fn trigger(&self) {
self.is_interrupted
.store(true, std::sync::atomic::Ordering::SeqCst);
self.notify.notify_one();
}
pub fn check(&self) -> bool {
self.is_interrupted
.load(std::sync::atomic::Ordering::SeqCst)
}
pub fn reset(&self) {
self.is_interrupted
.store(false, std::sync::atomic::Ordering::SeqCst);
}
}