workflow_egui/runtime/
signals.rs1use crate::imports::*;
2
3pub struct Signals {
4 runtime: Runtime,
5 iterations: AtomicU64,
6}
7
8impl Signals {
9 pub fn bind(runtime: &Runtime) {
10 let signals = Arc::new(Signals {
11 runtime: runtime.clone(),
12 iterations: AtomicU64::new(0),
13 });
14
15 ctrlc::set_handler(move || {
16 let v = signals.iterations.fetch_add(1, Ordering::SeqCst);
17
18 match v {
19 0 => {
20 println!("^SIGTERM - shutting down...");
22 signals
23 .runtime
24 .try_send_runtime_event(RuntimeEvent::Exit)
25 .unwrap_or_else(|e| {
26 println!("Error sending exit event: {:?}", e);
27 });
28 }
29 1 => {
30 println!("^SIGTERM - aborting...");
34 Runtime::abort();
35 }
36 _ => {
37 println!("^SIGTERM - halting");
39 std::process::exit(1);
40 }
41 }
42 })
43 .expect("Error setting signal handler");
44 }
45}