Skip to main content

reratui_runtime/
exit.rs

1use std::sync::atomic::{AtomicBool, Ordering};
2
3static GLOBAL_EXIT: AtomicBool = AtomicBool::new(false);
4
5/// Request the application to exit
6pub fn request_exit() {
7    GLOBAL_EXIT.store(true, Ordering::Release);
8}
9
10/// Check if exit has been requested
11pub fn should_exit() -> bool {
12    GLOBAL_EXIT.load(Ordering::Acquire)
13}
14
15/// Reset the exit flag (useful for tests)
16pub fn reset_exit() {
17    GLOBAL_EXIT.store(false, Ordering::Release);
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23
24    #[test]
25    fn test_exit_flag() {
26        assert!(!should_exit());
27        request_exit();
28        assert!(should_exit());
29        reset_exit();
30        assert!(!should_exit());
31    }
32}