smol/examples/ctrl-c.rs

18 lines
417 B
Rust
Raw Normal View History

2020-04-21 15:51:07 +00:00
// TODO: document
2020-04-19 09:29:52 +00:00
// Uses the `ctrlc` crate to set a handler that sends a message
// through an async channel.
2020-04-06 20:19:54 +00:00
use futures::prelude::*;
2020-03-26 13:57:06 +00:00
fn main() {
2020-04-06 20:19:54 +00:00
let (s, ctrl_c) = piper::chan(100);
let handle = move || drop(s.send(()).now_or_never());
ctrlc::set_handler(handle).unwrap();
2020-03-26 13:57:06 +00:00
smol::run(async {
println!("Waiting for Ctrl-C");
2020-04-06 20:19:54 +00:00
ctrl_c.recv().await;
2020-03-26 13:57:06 +00:00
println!("Done!");
})
}