elif_core/foundation/
lifecycle.rs1use std::sync::atomic::{AtomicBool, Ordering};
2use std::sync::Arc;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum LifecycleState {
7 Created,
8 Initializing,
9 Running,
10 Stopping,
11 Stopped,
12 Failed,
13}
14
15#[derive(Debug)]
17pub struct LifecycleManager {
18 state: Arc<AtomicBool>,
19}
20
21impl LifecycleManager {
22 pub fn new() -> Self {
24 Self {
25 state: Arc::new(AtomicBool::new(false)),
26 }
27 }
28
29 pub fn is_running(&self) -> bool {
31 self.state.load(Ordering::SeqCst)
32 }
33
34 pub fn set_running(&self, running: bool) {
36 self.state.store(running, Ordering::SeqCst);
37 }
38}
39
40impl Default for LifecycleManager {
41 fn default() -> Self {
42 Self::new()
43 }
44}