3 stable releases

1.2.0 May 30, 2020
1.1.0 May 1, 2020
1.0.0 Dec 16, 2019

#697 in Asynchronous

Download history 6556/week @ 2024-03-14 4037/week @ 2024-03-21 4383/week @ 2024-03-28 4138/week @ 2024-04-04 4354/week @ 2024-04-11 8499/week @ 2024-04-18 8953/week @ 2024-04-25 8501/week @ 2024-05-02 8775/week @ 2024-05-09 8686/week @ 2024-05-16 8378/week @ 2024-05-23 2110/week @ 2024-05-30 1139/week @ 2024-06-06 5943/week @ 2024-06-13 1749/week @ 2024-06-20 970/week @ 2024-06-27

10,165 downloads per month
Used in 9 crates (7 directly)

MIT/Apache

13KB
73 lines

async-ctrlc is an async wrapper of the ctrlc crate.

Build status Latest Version Documentation

Future example

use async_ctrlc::CtrlC;
use async_std::{prelude::FutureExt, task::sleep};
use std::time::Duration;

#[async_std::main]
async fn main() {
    let ctrlc = CtrlC::new().expect("cannot create Ctrl+C handler?");
    println!("Try to press Ctrl+C");
    ctrlc.race(async {
        let mut i = 0;
        loop {
            println!("... {}", i);
            sleep(Duration::from_secs(1)).await;
            i += 1;
        }
    }).await;
    println!("Quitting");
}

Stream example

use async_ctrlc::CtrlC;
use async_std::prelude::StreamExt as _;

#[async_std::main]
async fn main() {
    let ctrlc = CtrlC::new().expect("cannot create Ctrl+C handler?");
    println!("Try to press Ctrl+C 3 times");
    let mut stream = ctrlc.enumerate().take(3);
    while let Some((count, _)) = stream.next().await {
        println!("{} x Ctrl+C!", count + 1);
    }
    println!("Quitting");
}

License

MIT or Apache-2.0.

Dependencies

~1.5–8.5MB
~74K SLoC