3 stable releases

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

#839 in Asynchronous

Download history 1937/week @ 2024-09-09 1938/week @ 2024-09-16 2054/week @ 2024-09-23 2640/week @ 2024-09-30 1557/week @ 2024-10-07 2231/week @ 2024-10-14 1969/week @ 2024-10-21 2000/week @ 2024-10-28 1606/week @ 2024-11-04 1336/week @ 2024-11-11 1323/week @ 2024-11-18 1203/week @ 2024-11-25 1464/week @ 2024-12-02 1677/week @ 2024-12-09 1496/week @ 2024-12-16 443/week @ 2024-12-23

5,160 downloads per month
Used in 10 crates (8 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–7.5MB
~66K SLoC