mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
signal: Touch up the sighup-example slightly
This commit is contained in:
parent
36b58d8fa8
commit
010c2223ca
@ -2,7 +2,7 @@ extern crate futures;
|
|||||||
extern crate tokio_core;
|
extern crate tokio_core;
|
||||||
extern crate tokio_signal;
|
extern crate tokio_signal;
|
||||||
|
|
||||||
use futures::stream::Stream;
|
use futures::{Stream, Future};
|
||||||
use tokio_core::reactor::Core;
|
use tokio_core::reactor::Core;
|
||||||
use tokio_signal::unix::{Signal,SIGHUP};
|
use tokio_signal::unix::{Signal,SIGHUP};
|
||||||
|
|
||||||
@ -11,18 +11,19 @@ fn main() {
|
|||||||
let mut core = Core::new().unwrap();
|
let mut core = Core::new().unwrap();
|
||||||
|
|
||||||
// on Unix, we can listen to whatever signal we want, in this case: SIGHUP
|
// on Unix, we can listen to whatever signal we want, in this case: SIGHUP
|
||||||
let sighup = Signal::new(SIGHUP, &core.handle());
|
let stream = Signal::new(SIGHUP, &core.handle()).flatten_stream();
|
||||||
let stream = core.run(sighup).unwrap();
|
|
||||||
|
|
||||||
println!("Waiting for SIGHUPS (Ctrl+C to quit)");
|
println!("Waiting for SIGHUPS (Ctrl+C to quit)");
|
||||||
println!(" TIP: use `pkill -sighup sighup-example` from a second terminal to send a SIGHUP \
|
println!(" TIP: use `pkill -sighup sighup-example` from a second terminal \
|
||||||
to all processes named 'sighup-example' (i.e. this binary)");
|
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
|
// for_each is a powerful primitive provided by the Futures crate
|
||||||
// it turns a Stream into a Future that completes after all stream-items
|
// it turns a Stream into a Future that completes after all stream-items
|
||||||
// have been completed.
|
// have been completed.
|
||||||
let future = stream.for_each(|the_signal| {
|
let future = stream.for_each(|the_signal| {
|
||||||
println!("*Got a signal {}* 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(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user