3 stable releases

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

#1344 in Asynchronous

Download history 12013/week @ 2025-10-17 13424/week @ 2025-10-24 15249/week @ 2025-10-31 12779/week @ 2025-11-07 13180/week @ 2025-11-14 14820/week @ 2025-11-21 11245/week @ 2025-11-28 11595/week @ 2025-12-05 9495/week @ 2025-12-12 5281/week @ 2025-12-19 4403/week @ 2025-12-26 8321/week @ 2026-01-02 10432/week @ 2026-01-09 10960/week @ 2026-01-16 12130/week @ 2026-01-23 13163/week @ 2026-01-30

48,143 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.6–3.5MB
~74K SLoC