Files
tokio/tokio-signal/README.md
T

59 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
2018-09-01 11:18:51 +02:00
[![Travis Build Status][travis-badge]][travis-url]
[![Appveyor Build Status][appveyor-badge]][appveyor-url]
[travis-badge]: https://travis-ci.org/tokio-rs/tokio.svg?branch=master
[travis-url]: https://travis-ci.org/tokio-rs/tokio
[appveyor-badge]: https://ci.appveyor.com/api/projects/status/s83yxhy9qeb58va7/branch/master?svg=true
[appveyor-url]: https://ci.appveyor.com/project/carllerche/tokio/branch/master
2016-09-06 23:00:17 -07:00
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]
2018-08-25 09:50:00 -07:00
tokio-signal = "0.2"
2016-09-06 23:00:17 -07:00
```
Next you can use this in conjunction with the `tokio` 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;
2016-09-06 23:00:17 -07:00
extern crate tokio_signal;
2017-06-07 12:29:31 -07:00
use futures::{Future, Stream};
fn main() {
// 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().flatten_stream();
2017-06-07 12:29:31 -07:00
// Process each ctrl-c as it comes in
let prog = ctrl_c.for_each(|()| {
println!("ctrl-c received!");
Ok(())
});
tokio::run(prog.map_err(|err| panic!("{}", err)));
2017-06-07 12:29:31 -07:00
}
2016-09-06 23:00:17 -07:00
```
# License
2018-09-07 09:56:40 +02:00
This project is licensed the MIT license ([LICENSE](LICENSE) or
http://opensource.org/licenses/MIT).
2016-09-06 23:00:17 -07:00
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
2018-09-07 09:56:40 +02:00
for inclusion in Tokio by you, shall be licensed as MIT, without any additional
terms or conditions.