3 stable releases

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

#927 in Asynchronous

Download history 1954/week @ 2024-10-30 1382/week @ 2024-11-06 1446/week @ 2024-11-13 1333/week @ 2024-11-20 1281/week @ 2024-11-27 1491/week @ 2024-12-04 1633/week @ 2024-12-11 1103/week @ 2024-12-18 404/week @ 2024-12-25 1150/week @ 2025-01-01 1978/week @ 2025-01-08 2081/week @ 2025-01-15 2424/week @ 2025-01-22 2121/week @ 2025-01-29 2432/week @ 2025-02-05 1595/week @ 2025-02-12

8,904 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–8MB
~66K SLoC