diff options
| author | bors <bors@rust-lang.org> | 2017-06-01 05:24:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-06-01 05:24:11 +0000 |
| commit | 38efb2e1ccf210b0108d2b88ee9d4ddcd8e91a3a (patch) | |
| tree | fd62a4e7688baa1ef79d4d4ac559f487d64903e4 /src/libstd | |
| parent | e0cc22b4bae8007c59fbe58f2c104ecd743d746a (diff) | |
| parent | 9bd6dc73fc7fd46bf83ff17bea13a410efb1fc96 (diff) | |
| download | rust-38efb2e1ccf210b0108d2b88ee9d4ddcd8e91a3a.tar.gz rust-38efb2e1ccf210b0108d2b88ee9d4ddcd8e91a3a.zip | |
Auto merge of #42348 - frewsxcv:rollup, r=frewsxcv
Rollup of 9 pull requests - Successful merges: #42136, #42275, #42286, #42297, #42302, #42306, #42314, #42324, #42347 - Failed merges:
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sync/mpsc/mod.rs | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 69507cada2b..744868e2e23 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1252,14 +1252,43 @@ impl<T> Receiver<T> { /// /// # Examples /// + /// Successfully receiving value before encountering timeout: + /// + /// ```no_run + /// use std::thread; + /// use std::time::Duration; + /// use std::sync::mpsc; + /// + /// let (send, recv) = mpsc::channel(); + /// + /// thread::spawn(move || { + /// send.send('a').unwrap(); + /// }); + /// + /// assert_eq!( + /// recv.recv_timeout(Duration::from_millis(400)), + /// Ok('a') + /// ); + /// ``` + /// + /// Receiving an error upon reaching timeout: + /// /// ```no_run - /// use std::sync::mpsc::{self, RecvTimeoutError}; + /// use std::thread; /// use std::time::Duration; + /// use std::sync::mpsc; + /// + /// let (send, recv) = mpsc::channel(); /// - /// let (send, recv) = mpsc::channel::<()>(); + /// thread::spawn(move || { + /// thread::sleep(Duration::from_millis(800)); + /// send.send('a').unwrap(); + /// }); /// - /// let timeout = Duration::from_millis(100); - /// assert_eq!(Err(RecvTimeoutError::Timeout), recv.recv_timeout(timeout)); + /// assert_eq!( + /// recv.recv_timeout(Duration::from_millis(400)), + /// Err(mpsc::RecvTimeoutError::Timeout) + /// ); /// ``` #[stable(feature = "mpsc_recv_timeout", since = "1.12.0")] pub fn recv_timeout(&self, timeout: Duration) -> Result<T, RecvTimeoutError> { |
