| 1 | use std::sync::{ |
| 2 | Arc, |
| 3 | atomic::{AtomicBool, Ordering}, |
| 4 | }; |
| 5 | |
| 6 | #[derive(Clone, Default)] |
| 7 | pub struct EventBroker { |
| 8 | paused: Arc<AtomicBool>, |
| 9 | } |
| 10 | |
| 11 | impl EventBroker { |
| 12 | pub fn new() -> Self { |
| 13 | Self { |
| 14 | paused: Arc::new(AtomicBool::new(false)), |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | pub fn pause_events(&self) { |
| 19 | self.paused.store(true, Ordering::SeqCst); |
| 20 | } |
| 21 | |
| 22 | pub fn resume_events(&self) { |
| 23 | self.paused.store(false, Ordering::SeqCst); |
| 24 | } |
| 25 | |
| 26 | pub fn is_paused(&self) -> bool { |
| 27 | self.paused.load(Ordering::SeqCst) |
| 28 | } |
| 29 | } |
| 30 |