Crates.io | async-ctrlc |
lib.rs | async-ctrlc |
version | 1.2.0 |
source | src |
created_at | 2019-12-16 18:01:09.871201 |
updated_at | 2020-05-30 16:53:11.584663 |
description | Async wrapper of `ctrlc` |
homepage | https://github.com/kennytm/async-ctrlc |
repository | https://github.com/kennytm/async-ctrlc |
max_upload_size | |
id | 189808 |
size | 48,592 |
async-ctrlc
is an async wrapper of the ctrlc
crate.
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");
}
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");
}
MIT or Apache-2.0.