Merge pull request #703 from spacekookie/recv-docs

channel/recv: improving function docs and code example
mio-0-7
Yoshua Wuyts 5 years ago committed by GitHub
commit e026b7579a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -346,8 +346,9 @@ pub struct Receiver<T> {
impl<T> Receiver<T> { impl<T> Receiver<T> {
/// Receives a message from the channel. /// Receives a message from the channel.
/// ///
/// If the channel is empty and still has senders, this method will wait until a message is /// If the channel is emtpy and still has senders, this method
/// sent into the channel or until all senders get dropped. /// will wait until a message is sent into it. Once all senders
/// have been dropped it will return `None`.
/// ///
/// # Examples /// # Examples
/// ///
@ -362,10 +363,13 @@ impl<T> Receiver<T> {
/// task::spawn(async move { /// task::spawn(async move {
/// s.send(1).await; /// s.send(1).await;
/// s.send(2).await; /// s.send(2).await;
/// // Then we drop the sender
/// }); /// });
/// ///
/// assert_eq!(r.recv().await, Some(1)); /// assert_eq!(r.recv().await, Some(1));
/// assert_eq!(r.recv().await, Some(2)); /// assert_eq!(r.recv().await, Some(2));
///
/// // recv() returns `None`
/// assert_eq!(r.recv().await, None); /// assert_eq!(r.recv().await, None);
/// # /// #
/// # }) /// # })

Loading…
Cancel
Save