mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
sync: doc of watch::Sender::send
improved (#4959)
Current documentation of `sync:⌚:Sender::send` may be intepreted as the method failing if at some point in past the channel has been closed because every receiver has been dropped. This isn't true, however, as the channel could have been reopened by using `sync:⌚:Sender::subscribe`. This fix clarifies the behavior. Moreover, it is noted that on failure, the value isn't made available to future subscribers (but returned as part of the `SendError`). Fixes #4957.
This commit is contained in:
parent
f207e1afe4
commit
431ec68f93
@ -604,8 +604,22 @@ impl<T> Drop for Receiver<T> {
|
|||||||
impl<T> Sender<T> {
|
impl<T> Sender<T> {
|
||||||
/// Sends a new value via the channel, notifying all receivers.
|
/// Sends a new value via the channel, notifying all receivers.
|
||||||
///
|
///
|
||||||
/// This method fails if the channel has been closed, which happens when
|
/// This method fails if the channel is closed, which is the case when
|
||||||
/// every receiver has been dropped.
|
/// 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>> {
|
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.
|
// This is pretty much only useful as a hint anyway, so synchronization isn't critical.
|
||||||
if 0 == self.receiver_count() {
|
if 0 == self.receiver_count() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user