mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
signal: Ctrl+C example: add explanatory comments
This commit is contained in:
parent
175f9afea9
commit
f5eadc74f1
@ -6,12 +6,19 @@ use futures::stream::Stream;
|
||||
use tokio_core::reactor::Core;
|
||||
|
||||
fn main() {
|
||||
// set up a Tokio event loop
|
||||
let mut core = Core::new().unwrap();
|
||||
|
||||
// tokio_signal provides a convenience builder for Ctrl+C
|
||||
// this even works cross-platform, linux and windows!
|
||||
let ctrlc = tokio_signal::ctrl_c(&core.handle());
|
||||
let stream = core.run(ctrlc).unwrap();
|
||||
|
||||
println!("This program is now waiting for you to press Ctrl+C");
|
||||
|
||||
// Up until now, we haven't really DONE anything, just prepared
|
||||
// now it's time to actually schedule, and thus execute, the stream
|
||||
// on our event loop
|
||||
core.run(stream.for_each(|()| {
|
||||
println!("Ctrl-C received!");
|
||||
Ok(())
|
||||
|
Loading…
x
Reference in New Issue
Block a user