From aae835cc146c3eac301647ee170cc53dbeb913da Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Wed, 12 Feb 2020 01:38:20 +0100 Subject: [PATCH] channel/recv: improving function docs and code example At the moment it's not clear when and why recv returns Option, instead of just T. This changed comment makes it clear that None will only be returned once no data will ever be sent again (i.e. after all senders are gone). --- src/sync/channel.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sync/channel.rs b/src/sync/channel.rs index 2647f65..b42326b 100644 --- a/src/sync/channel.rs +++ b/src/sync/channel.rs @@ -346,8 +346,9 @@ pub struct Receiver { impl Receiver { /// Receives a message from the channel. /// - /// If the channel is empty and still has senders, this method will wait until a message is - /// sent into the channel or until all senders get dropped. + /// If the channel is emtpy and still has senders, this method + /// will wait until a message is sent into it. Once all senders + /// have been dropped it will return `None`. /// /// # Examples /// @@ -362,10 +363,13 @@ impl Receiver { /// task::spawn(async move { /// s.send(1).await; /// s.send(2).await; + /// // Then we drop the sender /// }); /// /// assert_eq!(r.recv().await, Some(1)); /// assert_eq!(r.recv().await, Some(2)); + /// + /// // recv() returns `None` /// assert_eq!(r.recv().await, None); /// # /// # })