diff --git a/examples/ctrl-c/src/main.rs b/examples/ctrl-c/src/main.rs index be8962215..16edd592a 100644 --- a/examples/ctrl-c/src/main.rs +++ b/examples/ctrl-c/src/main.rs @@ -16,13 +16,18 @@ fn main() { println!("This program is now waiting for you to press Ctrl+C"); + // for_each is a powerful primitive provided by the Futures crate + // it turns a Stream into a Future that completes after all stream-items + // have been completed. + let future = stream.for_each(|()| { + println!("Ctrl+C received!"); + Ok(()) + }); + // 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(()) - })).unwrap(); + core.run(future).unwrap(); println!("this won't be printed, because the received Ctrl+C will also kill the program"); unreachable!();