Module ctrlc
Simple handling of Ctrl+C for CLI programs.
ctrlc provides a simple, cross-platform way to set a handler
for the Ctrl+C signal (SIGINT on Unix, CTRL_C_EVENT on Windows).
It spawns a dedicated signal-handling thread
and invokes a user-provided closure when the signal is received.
The typical pattern is to pair a handler with an AtomicBool
that the main loop checks to know when to shut down gracefully.
Examples
Graceful shutdown with an atomic flag:
use Arc;
use ;
let running = new;
let r = running.clone;
set_handler.expect;
while running.load
println!;
Functions
- set_handler Register signal handler for Ctrl-C.
- try_set_handler The same as ctrlc::set_handler but errors if a handler already exists for the signal(s).