mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-26 00:00:16 +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
@@ -19,19 +19,16 @@ Next you can use this in conjunction with the `tokio-core` and `futures` crates:
|
||||
|
||||
```rust,no_run
|
||||
extern crate futures;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio;
|
||||
extern crate tokio_signal;
|
||||
|
||||
use tokio_core::reactor::Core;
|
||||
use futures::{Future, Stream};
|
||||
|
||||
fn main() {
|
||||
let mut core = Core::new().unwrap();
|
||||
let handle = core.handle();
|
||||
|
||||
// Create an infinite stream of "Ctrl+C" notifications. Each item received
|
||||
// on this stream may represent multiple ctrl-c signals.
|
||||
let ctrl_c = tokio_signal::ctrl_c(&handle).flatten_stream();
|
||||
let ctrl_c = tokio_signal::ctrl_c().flatten_stream();
|
||||
|
||||
// Process each ctrl-c as it comes in
|
||||
let prog = ctrl_c.for_each(|()| {
|
||||
@@ -39,7 +36,7 @@ fn main() {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
core.run(prog).unwrap();
|
||||
tokio::run(prog.map_err(|err| panic!("{}", err)));
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user