mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-19 00:00:09 +02:00
signal: refactor: Prefer the implicit handle passing used by tokio
This commit is contained in:
committed by
Carl Lerche
parent
209232befd
commit
e73b8a0cc9
+1
-1
@@ -19,7 +19,7 @@ fn main() {
|
||||
// the `flatten_stream()` convenience method lazily defers that
|
||||
// initialisation, allowing us to use it 'as if' it is already the
|
||||
// stream we want, reducing boilerplate Future-handling.
|
||||
let endless_stream = tokio_signal::ctrl_c(&core.handle().new_tokio_handle()).flatten_stream();
|
||||
let endless_stream = tokio_signal::ctrl_c().flatten_stream();
|
||||
// don't keep going forever: convert the endless stream to a bounded one.
|
||||
let limited_stream = endless_stream.take(STOP_AFTER);
|
||||
|
||||
|
||||
@@ -10,12 +10,10 @@ use tokio_signal::unix::{Signal, SIGINT, SIGTERM};
|
||||
|
||||
fn main() {
|
||||
let mut core = Core::new().unwrap();
|
||||
let handle = core.handle();
|
||||
let handle = handle.new_tokio_handle();
|
||||
|
||||
// Create a stream for each of the signals we'd like to handle.
|
||||
let sigint = Signal::new(SIGINT, &handle).flatten_stream();
|
||||
let sigterm = Signal::new(SIGTERM, &handle).flatten_stream();
|
||||
let sigint = Signal::new(SIGINT).flatten_stream();
|
||||
let sigterm = Signal::new(SIGTERM).flatten_stream();
|
||||
|
||||
// Use the `select` combinator to merge these two streams into one
|
||||
let stream = sigint.select(sigterm);
|
||||
|
||||
@@ -11,7 +11,7 @@ fn main() {
|
||||
let mut core = Core::new().unwrap();
|
||||
|
||||
// on Unix, we can listen to whatever signal we want, in this case: SIGHUP
|
||||
let stream = Signal::new(SIGHUP, &core.handle().new_tokio_handle()).flatten_stream();
|
||||
let stream = Signal::new(SIGHUP).flatten_stream();
|
||||
|
||||
println!("Waiting for SIGHUPS (Ctrl+C to quit)");
|
||||
println!(
|
||||
|
||||
Reference in New Issue
Block a user