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

tokio: add builder function for watch::Sender #5998

Merged
merged 6 commits into from
Sep 19, 2023
Merged
Changes from 3 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
20 changes: 20 additions & 0 deletions tokio/src/sync/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,26 @@ impl<T> Drop for Receiver<T> {
}

impl<T> Sender<T> {
/// Creates the sending-half of the [`watch`] channel.
///
/// See documentation of [`watch::channel`] for errors when calling this function.
/// Beware that attempting to send a value when no one subscribed to the channel will
nicflower marked this conversation as resolved.
Show resolved Hide resolved
/// return an error.
///
/// [`watch`]: crate::sync::watch
/// [`watch::channel`]: crate::sync::watch
///
/// # Examples
/// ```
/// let sender = tokio::sync::watch::Sender::new(0u8);
/// assert!(sender.send(3).is_err())
/// let _rec = sender.subscribe()
/// assert!(sender.send(4).is_ok())
nicflower marked this conversation as resolved.
Show resolved Hide resolved
pub fn new(init: T) -> Self {
let (tx, _) = channel(init);
tx
}

/// Sends a new value via the channel, notifying all receivers.
///
/// This method fails if the channel is closed, which is the case when
Expand Down
Loading