elif_core/foundation/
lifecycle.rs

1use std::sync::atomic::{AtomicBool, Ordering};
2use std::sync::Arc;
3
4/// Application lifecycle states
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum LifecycleState {
7    Created,
8    Initializing,
9    Running,
10    Stopping,
11    Stopped,
12    Failed,
13}
14
15/// Simple lifecycle manager for the framework
16#[derive(Debug)]
17pub struct LifecycleManager {
18    state: Arc<AtomicBool>,
19}
20
21impl LifecycleManager {
22    /// Create a new lifecycle manager
23    pub fn new() -> Self {
24        Self {
25            state: Arc::new(AtomicBool::new(false)),
26        }
27    }
28    
29    /// Check if the lifecycle manager is running
30    pub fn is_running(&self) -> bool {
31        self.state.load(Ordering::SeqCst)
32    }
33    
34    /// Set running state
35    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}