diff options
author | Ivan Petkov <ivanppetkov@gmail.com> | 2019-07-20 15:12:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-20 15:12:53 -0700 |
commit | d9688bc09485e0c3e732a5ed3e3749f5e893aed9 (patch) | |
tree | fbda5ce255504831ae2162ebdd9f06f8a3404955 | |
parent | 320a5fdca7637e4045d4e3c8a7e592e3a833b1da (diff) |
signal: change unix::Signal to return () instead of signum (#1330)
* This simplifies the API surface by returning () instead of the signal
number that was used during registration. This also more closely mirrors
the cross-platform `CtrlC` event stream API
* This is a **breaking change**
-rw-r--r-- | tokio-signal/CHANGELOG.md | 3 | ||||
-rw-r--r-- | tokio-signal/examples/multiple.rs | 4 | ||||
-rw-r--r-- | tokio-signal/examples/sighup-example.rs | 8 | ||||
-rw-r--r-- | tokio-signal/src/unix.rs | 7 | ||||
-rw-r--r-- | tokio-signal/tests/twice.rs | 4 |
5 files changed, 12 insertions, 14 deletions
diff --git a/tokio-signal/CHANGELOG.md b/tokio-signal/CHANGELOG.md index 90a8cb2e..5e8b9434 100644 --- a/tokio-signal/CHANGELOG.md +++ b/tokio-signal/CHANGELOG.md @@ -3,6 +3,9 @@ ### Changed - **Breaking:** `windows::Event` has been removed in favor of `CtrlC` and a separate `windows::CtrlBreak` struct. +- **Breaking:** `ctrl_c{,_with_handle}` has been replaced with a `CtrlC` struct +(which can be constructed via `CtrlC::{new, with_handle}`. +- **Breaking:** `unix::Signal` returns `()` instead of the signal number used in registration # 0.2.9 diff --git a/tokio-signal/examples/multiple.rs b/tokio-signal/examples/multiple.rs index 62d4b855..0c5a17fd 100644 --- a/tokio-signal/examples/multiple.rs +++ b/tokio-signal/examples/multiple.rs @@ -11,8 +11,8 @@ mod platform { pub async fn main() { // Create a stream for each of the signals we'd like to handle. - let sigint = Signal::new(SIGINT).await.unwrap(); - let sigterm = Signal::new(SIGTERM).await.unwrap(); + let sigint = Signal::new(SIGINT).await.unwrap().map(|_| SIGINT); + let sigterm = Signal::new(SIGTERM).await.unwrap().map(|_| SIGTERM); // Use the `select` combinator to merge these two streams into one let stream = stream::select(sigint, sigterm); diff --git a/tokio-signal/examples/sighup-example.rs b/tokio-signal/examples/sighup-example.rs index 08972b9e..ef84194d 100644 --- a/tokio-signal/examples/sighup-example.rs +++ b/tokio-signal/examples/sighup-example.rs @@ -20,12 +20,8 @@ mod platform { // Up until now, we haven't really DONE anything, just prepared // our futures, now it's time to actually await the results! - while let Some(the_signal) = stream.next().await { - println!( - "*Got signal {:#x}* I should probably reload my config \ - or something", - the_signal - ); + while let Some(_) = stream.next().await { + println!("*Got signal* I should probably reload my config or something"); } } } diff --git a/tokio-signal/src/unix.rs b/tokio-signal/src/unix.rs index 5e2d3c23..d42cb18d 100644 --- a/tokio-signal/src/unix.rs +++ b/tokio-signal/src/unix.rs @@ -254,7 +254,6 @@ impl Driver { #[derive(Debug)] pub struct Signal { driver: Driver, - signal: c_int, rx: Receiver<()>, } @@ -321,7 +320,7 @@ impl Signal { let (tx, rx) = channel(1); globals().register_listener(signal as EventId, tx); - Ok(Signal { driver, rx, signal }) + Ok(Signal { driver, rx }) }) .boxed() } @@ -332,12 +331,12 @@ impl Signal { } impl Stream for Signal { - type Item = c_int; + type Item = (); fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { let _ = Pin::new(&mut self.driver).poll(cx); - self.rx.poll_recv(cx).map(|item| item.map(|()| self.signal)) + self.rx.poll_recv(cx) } } diff --git a/tokio-signal/tests/twice.rs b/tokio-signal/tests/twice.rs index 75aa8f8a..b5638551 100644 --- a/tokio-signal/tests/twice.rs +++ b/tokio-signal/tests/twice.rs @@ -16,8 +16,8 @@ async fn twice() { for _ in 0..2 { send_signal(libc::SIGUSR1); - let (num, sig) = with_timeout(signal.into_future()).await; - assert_eq!(num, Some(libc::SIGUSR1)); + let (item, sig) = with_timeout(signal.into_future()).await; + assert_eq!(item, Some(())); signal = sig; } |