3 stable releases

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

#1449 in Asynchronous

Download history 11235/week @ 2026-05-04 12342/week @ 2026-05-11 15972/week @ 2026-05-18 13816/week @ 2026-05-25 14536/week @ 2026-06-01 15085/week @ 2026-06-08 16476/week @ 2026-06-15 16492/week @ 2026-06-22 16243/week @ 2026-06-29 14386/week @ 2026-07-06 14715/week @ 2026-07-13 17362/week @ 2026-07-20 14908/week @ 2026-07-27 15245/week @ 2026-08-03 13986/week @ 2026-08-10 14025/week @ 2026-08-17

59,149 downloads per month
Used in 11 crates (10 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.6–3.5MB
~70K SLoC