3 stable releases

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

#97 in Asynchronous

Download history 367/week @ 2020-11-07 334/week @ 2020-11-14 445/week @ 2020-11-21 339/week @ 2020-11-28 587/week @ 2020-12-05 525/week @ 2020-12-12 328/week @ 2020-12-19 276/week @ 2020-12-26 372/week @ 2021-01-02 303/week @ 2021-01-09 636/week @ 2021-01-16 427/week @ 2021-01-23 394/week @ 2021-01-30 545/week @ 2021-02-06 2919/week @ 2021-02-13 832/week @ 2021-02-20

2,608 downloads per month
Used in 2 crates

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

~220KB