Crate ctrlc [] [src]

A simple easy to use wrapper around Ctrl-C.

Example

extern crate ctrlc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

fn main() {
    let running = Arc::new(AtomicBool::new(true));
    let r = running.clone();
    ctrlc::set_handler(move || {
        r.store(false, Ordering::SeqCst);
    });
    println!("Waiting for Ctrl-C...");
    while running.load(Ordering::SeqCst) {}
    println!("Got it! Exiting...");
}

Functions

set_handler

Sets up the signal handler for Ctrl-C using default polling rate of 100ms.

set_handler_with_polling_rate

Sets up the signal handler for Ctrl-C using a custom polling rate. The polling rate is the amount of time the internal spinloop of CtrlC sleeps between iterations. Because condition variables are not safe to use inside a signal handler, CtrlC (from version 1.1.0) uses a spinloop and an atomic boolean instead.