Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Documentation for Signals #5459

Merged
merged 3 commits into from Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions tokio/src/signal/unix.rs
Expand Up @@ -292,7 +292,11 @@ fn signal_enable(signal: SignalKind, handle: &Handle) -> io::Result<()> {
}
}

/// A stream of events for receiving a particular type of OS signal.
/// An event for receiving a particular type of OS signal.
///
/// The signal can be turned into a `Stream` using [`SignalStream`].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// An event for receiving a particular type of OS signal.
///
/// The signal can be turned into a `Stream` using [`SignalStream`].
/// A listener for receiving a particular type of OS signal.
///
/// The listener can be turned into a `Stream` using [`SignalStream`].

///
/// [`SignalStream`]: https://docs.rs/tokio-stream/latest/tokio_stream/wrappers/struct.SignalStream.html
///
/// In general signal handling on Unix is a pretty tricky topic, and this
/// structure is no exception! There are some important limitations to keep in
Expand All @@ -307,9 +311,6 @@ fn signal_enable(signal: SignalKind, handle: &Handle) -> io::Result<()> {
/// Once `poll` has been called, however, a further signal is guaranteed to
/// be yielded as an item.
///
/// Put another way, any element pulled off the returned stream corresponds to
/// *at least one* signal, but possibly more.
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-///   Put another way, any element pulled off the returned stream corresponds to
-///   *at least one* signal, but possibly more.
+///   Put another way, any element pulled off the returned listener corresponds to
+///   *at least one* signal, but possibly more.

/// * Signal handling in general is relatively inefficient. Although some
/// improvements are possible in this crate, it's recommended to not plan on
/// having millions of signal channels open.
Expand Down Expand Up @@ -345,11 +346,11 @@ fn signal_enable(signal: SignalKind, handle: &Handle) -> io::Result<()> {
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // An infinite stream of hangup signals.
/// let mut stream = signal(SignalKind::hangup())?;
/// let mut sig = signal(SignalKind::hangup())?;
///
/// // Print whenever a HUP signal is received
/// loop {
/// stream.recv().await;
/// sig.recv().await;
/// println!("got signal HUP");
/// }
/// }
Expand All @@ -360,7 +361,7 @@ pub struct Signal {
inner: RxFuture,
}

/// Creates a new stream which will receive notifications when the current
/// Creates a new signal which will receive notifications when the current
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Creates a new signal which will receive notifications when the current
/// Creates a new listener which will receive notifications when the current

/// process receives the specified signal `kind`.
///
/// This function will create a new stream which binds to the default reactor.
Expand Down
33 changes: 20 additions & 13 deletions tokio/src/signal/windows.rs
Expand Up @@ -22,7 +22,7 @@ pub(crate) use self::imp::{OsExtraData, OsStorage};
#[path = "windows/stub.rs"]
mod imp;

/// Creates a new stream which receives "ctrl-c" notifications sent to the
/// Creates a new event which receives "ctrl-c" notifications sent to the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Creates a new event which receives "ctrl-c" notifications sent to the
/// Creates a new listener which receives "ctrl-c" notifications sent to the

/// process.
///
/// # Examples
Expand Down Expand Up @@ -50,14 +50,18 @@ pub fn ctrl_c() -> io::Result<CtrlC> {
})
}

/// Represents a stream which receives "ctrl-c" notifications sent to the process
/// Represents an event which receives "ctrl-c" notifications sent to the process
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Represents an event which receives "ctrl-c" notifications sent to the process
/// Represents a listener which receives "ctrl-c" notifications sent to the process

/// via `SetConsoleCtrlHandler`.
///
/// A notification to this process notifies *all* streams listening for
/// This event can be turned into a `Stream` using [`CtrlCStream`].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// This event can be turned into a `Stream` using [`CtrlCStream`].
/// This listener can be turned into a `Stream` using [`CtrlCStream`].

///
/// [`CtrlCStream`]: https://docs.rs/tokio-stream/latest/tokio_stream/wrappers/struct.CtrlCStream.html
///
/// A notification to this process notifies *all* receivers for
/// this event. Moreover, the notifications **are coalesced** if they aren't processed
/// quickly enough. This means that if two notifications are received back-to-back,
/// then the stream may only receive one item about the two notifications.
#[must_use = "streams do nothing unless polled"]
/// then the receiver may only receive one item about the two notifications.
#[must_use = "events do nothing unless polled"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would favor using "listener" on these 2 lines as well.

#[derive(Debug)]
pub struct CtrlC {
inner: RxFuture,
Expand All @@ -66,7 +70,7 @@ pub struct CtrlC {
impl CtrlC {
/// Receives the next signal notification event.
///
/// `None` is returned if no more events can be received by this stream.
/// `None` is returned if no more events can be received by the `RxFuture`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should say "the CtrlC". The RxFuture type is an internal implementation detail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or "this listener"

///
/// # Examples
///
Expand All @@ -75,12 +79,11 @@ impl CtrlC {
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // An infinite stream of CTRL-C events.
/// let mut stream = ctrl_c()?;
/// let mut signal = ctrl_c()?;
///
/// // Print whenever a CTRL-C event is received.
/// for countdown in (0..3).rev() {
/// stream.recv().await;
/// signal.recv().await;
/// println!("got CTRL-C. {} more to exit", countdown);
/// }
///
Expand All @@ -94,7 +97,7 @@ impl CtrlC {
/// Polls to receive the next signal notification event, outside of an
/// `async` context.
///
/// `None` is returned if no more events can be received by this stream.
/// `None` is returned if no more events can be received.
///
/// # Examples
///
Expand Down Expand Up @@ -127,11 +130,15 @@ impl CtrlC {
/// Represents a stream which receives "ctrl-break" notifications sent to the process
/// via `SetConsoleCtrlHandler`.
///
/// A notification to this process notifies *all* streams listening for
/// This event can be turned into a `Stream` using [`CtrlBreakStream`].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// This event can be turned into a `Stream` using [`CtrlBreakStream`].
/// This listener can be turned into a `Stream` using [`CtrlBreakStream`].

///
/// [`CtrlBreakStream`]: https://docs.rs/tokio-stream/latest/tokio_stream/wrappers/struct.CtrlBreakStream.html
///
/// A notification to this process notifies *all* receivers for
/// this event. Moreover, the notifications **are coalesced** if they aren't processed
/// quickly enough. This means that if two notifications are received back-to-back,
/// then the stream may only receive one item about the two notifications.
#[must_use = "streams do nothing unless polled"]
/// then the receiver may only receive one item about the two notifications.
#[must_use = "events do nothing unless polled"]
#[derive(Debug)]
pub struct CtrlBreak {
inner: RxFuture,
Expand Down