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

sync: doc of watch::Sender::send improved #4959

Merged
merged 4 commits into from
Sep 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions tokio/src/sync/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,22 @@ impl<T> Drop for Receiver<T> {
impl<T> Sender<T> {
/// Sends a new value via the channel, notifying all receivers.
///
/// This method fails if the channel has been closed, which happens when
/// every receiver has been dropped.
/// This method fails if the channel is closed, which is the case when
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be worth adding something like "unlike the other methods for sending" to emphasize that only this method fails in this way.

Copy link
Contributor Author

@JanBeh JanBeh Aug 30, 2022

Choose a reason for hiding this comment

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

Thank you for pointing that out; I added another note, mentioning that the other send methods can be used to send a value even if there isn't any receiver.

/// every receiver has been dropped. It is possible to reopen the channel
/// using the [`subscribe`] method. However, when `send` fails, the value
/// isn't made available for future receivers (but returned with the
/// [`SendError`]).
///
/// To always make a new value available for future receivers, even if no
/// receiver currently exists, one of the other send methods
/// ([`send_if_modified`], [`send_modify`], or [`send_replace`]) can be
/// used instead.
///
/// [`subscribe`]: Sender::subscribe
/// [`SendError`]: error::SendError
/// [`send_if_modified`]: Sender::send_if_modified
/// [`send_modify`]: Sender::send_modify
/// [`send_replace`]: Sender::send_replace
pub fn send(&self, value: T) -> Result<(), error::SendError<T>> {
// This is pretty much only useful as a hint anyway, so synchronization isn't critical.
if 0 == self.receiver_count() {
Expand Down