apalis_core/poller/
controller.rs1use std::sync::{
2 atomic::{AtomicUsize, Ordering},
3 Arc,
4};
5
6use super::{PLUGGED, STOPPED, UNPLUGGED};
7
8#[derive(Debug, Clone)]
12pub struct Controller {
13 pub(super) state: Arc<AtomicUsize>,
14}
15
16impl Controller {
17 pub fn new() -> Self {
19 Controller {
20 state: Arc::new(AtomicUsize::new(PLUGGED)),
21 }
22 }
23
24 pub fn plug(&self) {
26 self.state.store(PLUGGED, Ordering::Relaxed);
27 }
28
29 pub fn unplug(&self) {
31 self.state.store(UNPLUGGED, Ordering::Relaxed);
32 }
33
34 pub fn is_plugged(&self) -> bool {
36 self.state.load(Ordering::Relaxed) == PLUGGED
37 }
38
39 pub fn stop(&self) {
41 self.state.store(STOPPED, Ordering::Relaxed);
42 }
43
44 pub fn is_stopped(&self) -> bool {
46 self.state.load(Ordering::Relaxed) == STOPPED
47 }
48}
49
50impl Default for Controller {
51 fn default() -> Self {
52 Self::new()
53 }
54}