1extern crate graceful;
2
3use std::sync::atomic::{ATOMIC_BOOL_INIT, AtomicBool, Ordering};
4use std::time::Duration;
5use std::thread;
6
7use graceful::SignalGuard;
8
9static STOP: AtomicBool = ATOMIC_BOOL_INIT;
10
11fn main() {
12 let signal_guard = SignalGuard::new();
13
14 let handle = thread::spawn(|| {
15 println!("Worker thread started. Type Ctrl+C to stop.");
16 while !STOP.load(Ordering::Acquire) {
17 println!("working...");
18 thread::sleep(Duration::from_millis(500));
19 }
20 println!("Bye.");
21 });
22
23 signal_guard.at_exit(move |sig| {
24 println!("Signal {} received.", sig);
25 STOP.store(true, Ordering::Release);
26 handle.join().unwrap();
27 });
28}