diff options
author | Ivan Petkov <ivanppetkov@gmail.com> | 2019-08-13 21:07:22 -0700 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2019-08-13 21:07:22 -0700 |
commit | 338b37884a73782fe72d4e9a0616010bcd12180e (patch) | |
tree | a56fde0234b07cd418cc6da3b54770435302561b /tokio-signal/examples/multiple.rs | |
parent | 513326e01da05261fbb05f722836c7cb80552773 (diff) |
signal: Add SignalKind for registering signals more easily (#1430)
This avoids having consumers import libc for common signals, and it
improves discoverability since users need not be aware that libc
contains all supported constants.
Diffstat (limited to 'tokio-signal/examples/multiple.rs')
-rw-r--r-- | tokio-signal/examples/multiple.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/tokio-signal/examples/multiple.rs b/tokio-signal/examples/multiple.rs index 5157fb1b..7732d221 100644 --- a/tokio-signal/examples/multiple.rs +++ b/tokio-signal/examples/multiple.rs @@ -7,12 +7,14 @@ #[cfg(unix)] mod platform { use futures_util::stream::{self, StreamExt}; - use tokio_signal::unix::{Signal, SIGINT, SIGTERM}; + use tokio_signal::unix::{Signal, SignalKind}; pub async fn main() { // Create a stream for each of the signals we'd like to handle. - let sigint = Signal::new(SIGINT).unwrap().map(|_| SIGINT); - let sigterm = Signal::new(SIGTERM).unwrap().map(|_| SIGTERM); + let sigint = Signal::new(SignalKind::sigint()).unwrap().map(|_| "SIGINT"); + let sigterm = Signal::new(SignalKind::sigterm()) + .unwrap() + .map(|_| "SIGTERM"); // Use the `select` combinator to merge these two streams into one let stream = stream::select(sigint, sigterm); @@ -27,13 +29,8 @@ mod platform { let (item, _rest) = stream.into_future().await; // Figure out which signal we received - let item = item.ok_or("received no signal").unwrap(); - if item == SIGINT { - println!("received SIGINT"); - } else { - assert_eq!(item, SIGTERM); - println!("received SIGTERM"); - } + let msg = item.ok_or("received no signal").unwrap(); + println!("received {}", msg); } } |