From 77ca8a934cf76ec74144ec11e78ae7c7efbe910a Mon Sep 17 00:00:00 2001 From: Fuyang Liu Date: Fri, 5 Feb 2021 19:43:58 +0100 Subject: [PATCH] signal: make Signal::poll_recv method public (#3383) Signed-off-by: Fuyang Liu --- tokio/src/signal/unix.rs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tokio/src/signal/unix.rs b/tokio/src/signal/unix.rs index fc0f16d4eb0..0de875adb21 100644 --- a/tokio/src/signal/unix.rs +++ b/tokio/src/signal/unix.rs @@ -397,7 +397,41 @@ impl Signal { poll_fn(|cx| self.poll_recv(cx)).await } - pub(crate) fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll> { + /// Polls to receive the next signal notification event, outside of an + /// `async` context. + /// + /// This method returns: + /// + /// * `Poll::Pending` if no signals are available but the channel is not + /// closed. + /// * `Poll::Ready(Some(()))` if a signal is available. + /// * `Poll::Ready(None)` if the channel has been closed and all signals + /// sent before it was closed have been received. + /// + /// # Examples + /// + /// Polling from a manually implemented future + /// + /// ```rust,no_run + /// use std::pin::Pin; + /// use std::future::Future; + /// use std::task::{Context, Poll}; + /// use tokio::signal::unix::Signal; + /// + /// struct MyFuture { + /// signal: Signal, + /// } + /// + /// impl Future for MyFuture { + /// type Output = Option<()>; + /// + /// fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + /// println!("polling MyFuture"); + /// self.signal.poll_recv(cx) + /// } + /// } + /// ``` + pub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll> { self.rx.poll_recv(cx) }