Files
tokio/README.md
T

62 lines
1.5 KiB
Markdown
Raw Normal View History

2016-09-06 23:00:17 -07:00
# tokio-signal
An implementation of Unix signal handling for Tokio
[![Build Status](https://travis-ci.org/alexcrichton/tokio-signal.svg?branch=master)](https://travis-ci.org/alexcrichton/tokio-signal)
2017-01-12 10:32:16 -08:00
[Documentation](https://docs.rs/tokio-signal)
2016-09-06 23:00:17 -07:00
## Usage
First, add this to your `Cargo.toml`:
```toml
[dependencies]
2017-01-12 10:32:16 -08:00
tokio-signal = "0.1"
2016-09-06 23:00:17 -07:00
```
2017-06-19 14:38:02 +02:00
Next you can use this in conjunction with the `tokio-core` and `futures` crates:
2016-09-06 23:00:17 -07:00
2017-06-07 12:29:31 -07:00
```rust,no_run
extern crate futures;
extern crate tokio_core;
2016-09-06 23:00:17 -07:00
extern crate tokio_signal;
2017-06-07 12:29:31 -07:00
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();
// Process each ctrl-c as it comes in
let prog = ctrl_c.for_each(|()| {
println!("ctrl-c received!");
Ok(())
});
core.run(prog).unwrap();
}
2016-09-06 23:00:17 -07:00
```
# License
This project is licensed under either of
2016-09-06 23:00:17 -07:00
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)
2016-09-06 23:00:17 -07:00
at your option.
2016-09-06 23:00:17 -07:00
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.