@@ -768,6 +768,48 @@ impl<T> Receiver<T> {
768
768
/// If the corresponding `Sender` has disconnected, or it disconnects while
769
769
/// this call is blocking, this call will wake up and return `Err` to
770
770
/// indicate that no more messages can ever be received on this channel.
771
+ /// However, since channels are buffered, messages sent before the disconnect
772
+ /// will still be properly received.
773
+ ///
774
+ /// # Examples
775
+ ///
776
+ /// ```
777
+ /// use std::sync::mpsc;
778
+ /// use std::thread;
779
+ ///
780
+ /// let (send, recv) = mpsc::channel();
781
+ /// let handle = thread::spawn(move || {
782
+ /// send.send(1u8).unwrap();
783
+ /// });
784
+ ///
785
+ /// handle.join().unwrap();
786
+ ///
787
+ /// assert_eq!(Ok(1), recv.recv());
788
+ /// ```
789
+ ///
790
+ /// Buffering behavior:
791
+ ///
792
+ /// ```
793
+ /// use std::sync::mpsc;
794
+ /// use std::thread;
795
+ /// use std::sync::mpsc::RecvError;
796
+ ///
797
+ /// let (send, recv) = mpsc::channel();
798
+ /// let handle = thread::spawn(move || {
799
+ /// send.send(1u8).unwrap();
800
+ /// send.send(2).unwrap();
801
+ /// send.send(3).unwrap();
802
+ /// drop(send);
803
+ /// });
804
+ ///
805
+ /// // wait for the thread to join so we ensure the sender is dropped
806
+ /// handle.join().unwrap();
807
+ ///
808
+ /// assert_eq!(Ok(1), recv.recv());
809
+ /// assert_eq!(Ok(2), recv.recv());
810
+ /// assert_eq!(Ok(3), recv.recv());
811
+ /// assert_eq!(Err(RecvError), recv.recv());
812
+ /// ```
771
813
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
772
814
pub fn recv ( & self ) -> Result < T , RecvError > {
773
815
loop {
0 commit comments