@@ -1252,14 +1252,43 @@ impl<T> Receiver<T> {
12521252 ///
12531253 /// # Examples
12541254 ///
1255+ /// Successfully receiving value before encountering timeout:
1256+ ///
1257+ /// ```no_run
1258+ /// use std::thread;
1259+ /// use std::time::Duration;
1260+ /// use std::sync::mpsc;
1261+ ///
1262+ /// let (send, recv) = mpsc::channel();
1263+ ///
1264+ /// thread::spawn(move || {
1265+ /// send.send('a').unwrap();
1266+ /// });
1267+ ///
1268+ /// assert_eq!(
1269+ /// recv.recv_timeout(Duration::from_millis(400)),
1270+ /// Ok('a')
1271+ /// );
1272+ /// ```
1273+ ///
1274+ /// Receiving an error upon reaching timeout:
1275+ ///
12551276 /// ```no_run
1256- /// use std::sync::mpsc::{self, RecvTimeoutError} ;
1277+ /// use std::thread ;
12571278 /// use std::time::Duration;
1279+ /// use std::sync::mpsc;
1280+ ///
1281+ /// let (send, recv) = mpsc::channel();
12581282 ///
1259- /// let (send, recv) = mpsc::channel::<()>();
1283+ /// thread::spawn(move || {
1284+ /// thread::sleep(Duration::from_millis(800));
1285+ /// send.send('a').unwrap();
1286+ /// });
12601287 ///
1261- /// let timeout = Duration::from_millis(100);
1262- /// assert_eq!(Err(RecvTimeoutError::Timeout), recv.recv_timeout(timeout));
1288+ /// assert_eq!(
1289+ /// recv.recv_timeout(Duration::from_millis(400)),
1290+ /// Err(mpsc::RecvTimeoutError::Timeout)
1291+ /// );
12631292 /// ```
12641293 #[ stable( feature = "mpsc_recv_timeout" , since = "1.12.0" ) ]
12651294 pub fn recv_timeout ( & self , timeout : Duration ) -> Result < T , RecvTimeoutError > {
0 commit comments