mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-21 00:00:10 +02:00
signal: Run rustfmt 0.4.2
This commit is contained in:
committed by
Carl Lerche
parent
7a24ed7509
commit
2848df9b6c
+10
-6
@@ -2,7 +2,7 @@ extern crate futures;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio_signal;
|
||||
|
||||
use futures::{Stream, Future};
|
||||
use futures::{Future, Stream};
|
||||
use tokio_core::reactor::Core;
|
||||
|
||||
/// how many signals to handle before exiting
|
||||
@@ -26,25 +26,29 @@ fn main() {
|
||||
// how many Ctrl+C have we received so far?
|
||||
let mut counter = 0;
|
||||
|
||||
println!("This program is now waiting for you to press Ctrl+C {0} times.
|
||||
println!(
|
||||
"This program is now waiting for you to press Ctrl+C {0} times.
|
||||
* If running via `cargo run --example ctrl-c`, Ctrl+C also kills it, \
|
||||
due to https://github.com/rust-lang-nursery/rustup.rs/issues/806
|
||||
* If running the binary directly, the Ctrl+C is properly trapped.
|
||||
Terminate by repeating Ctrl+C {0} times, or ahead of time by \
|
||||
opening a second terminal and issuing `pkill -sigkil ctrl-c`",
|
||||
STOP_AFTER);
|
||||
STOP_AFTER
|
||||
);
|
||||
|
||||
// Stream::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, or the first time the closure returns an error
|
||||
let future = limited_stream.for_each(|()| {
|
||||
|
||||
// Note how we manipulate the counter without any fancy synchronisation.
|
||||
// The borrowchecker realises there can't be any conflicts, so the closure
|
||||
// can just capture it.
|
||||
counter += 1;
|
||||
println!("Ctrl+C received {} times! {} more before exit",
|
||||
counter, STOP_AFTER-counter);
|
||||
println!(
|
||||
"Ctrl+C received {} times! {} more before exit",
|
||||
counter,
|
||||
STOP_AFTER - counter
|
||||
);
|
||||
|
||||
// return Ok-result to continue handling the stream
|
||||
Ok(())
|
||||
|
||||
@@ -4,7 +4,7 @@ extern crate futures;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio_signal;
|
||||
|
||||
use futures::{Stream, Future};
|
||||
use futures::{Future, Stream};
|
||||
use tokio_core::reactor::Core;
|
||||
use tokio_signal::unix::{Signal, SIGINT, SIGTERM};
|
||||
|
||||
@@ -21,9 +21,11 @@ fn main() {
|
||||
|
||||
// Wait for a signal to arrive
|
||||
println!("Waiting for SIGINT or SIGTERM");
|
||||
println!(" TIP: use `pkill -sigint multiple` from a second terminal \
|
||||
to send a SIGINT to all processes named 'multiple' \
|
||||
(i.e. this binary)");
|
||||
println!(
|
||||
" TIP: use `pkill -sigint multiple` from a second terminal \
|
||||
to send a SIGINT to all processes named 'multiple' \
|
||||
(i.e. this binary)"
|
||||
);
|
||||
let (item, _rest) = core.run(stream.into_future()).ok().unwrap();
|
||||
|
||||
// Figure out which signal we received
|
||||
@@ -35,4 +37,3 @@ fn main() {
|
||||
println!("received SIGTERM");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ extern crate futures;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio_signal;
|
||||
|
||||
use futures::{Stream, Future};
|
||||
use futures::{Future, Stream};
|
||||
use tokio_core::reactor::Core;
|
||||
use tokio_signal::unix::{Signal,SIGHUP};
|
||||
use tokio_signal::unix::{Signal, SIGHUP};
|
||||
|
||||
fn main() {
|
||||
// set up a Tokio event loop
|
||||
@@ -14,16 +14,21 @@ fn main() {
|
||||
let stream = Signal::new(SIGHUP, &core.handle()).flatten_stream();
|
||||
|
||||
println!("Waiting for SIGHUPS (Ctrl+C to quit)");
|
||||
println!(" TIP: use `pkill -sighup sighup-example` from a second terminal \
|
||||
to send a SIGHUP to all processes named 'sighup-example' \
|
||||
(i.e. this binary)");
|
||||
println!(
|
||||
" TIP: use `pkill -sighup sighup-example` from a second terminal \
|
||||
to send a SIGHUP to all processes named 'sighup-example' \
|
||||
(i.e. this binary)"
|
||||
);
|
||||
|
||||
// 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(|the_signal| {
|
||||
println!("*Got signal {:#x}* I should probably reload my config \
|
||||
or something", the_signal);
|
||||
println!(
|
||||
"*Got signal {:#x}* I should probably reload my config \
|
||||
or something",
|
||||
the_signal
|
||||
);
|
||||
Ok(())
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user