From 4cf59304c1e112c3b0fbedc6034b2a469fb9fce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= Date: Tue, 7 Apr 2015 20:35:54 +0200 Subject: [PATCH 1/2] Remove incorrect example from docs --- src/libstd/sync/mpsc/mod.rs | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index c80182ec07d..a955f88164c 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -113,32 +113,6 @@ //! rx.recv().unwrap(); //! ``` //! -//! Reading from a channel with a timeout requires to use a Timer together -//! with the channel. You can use the `select!` macro to select either and -//! handle the timeout case. This first example will break out of the loop -//! after 10 seconds no matter what: -//! -//! ```no_run -//! # #![feature(std_misc, old_io)] -//! use std::sync::mpsc::channel; -//! use std::old_io::timer::Timer; -//! use std::time::Duration; -//! -//! let (tx, rx) = channel::(); -//! let mut timer = Timer::new().unwrap(); -//! let timeout = timer.oneshot(Duration::seconds(10)); -//! -//! loop { -//! select! { -//! val = rx.recv() => println!("Received {}", val.unwrap()), -//! _ = timeout.recv() => { -//! println!("timed out, total time was more than 10 seconds"); -//! break; -//! } -//! } -//! } -//! ``` -//! //! This second example is more costly since it allocates a new timer every //! time a message is received, but it allows you to timeout after the channel //! has been inactive for 5 seconds: From 4695bf070585ec74c3c7fb396c11b4f728f6866a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= Date: Tue, 7 Apr 2015 21:46:14 +0200 Subject: [PATCH 2/2] Remove another invalid example --- src/libstd/sync/mpsc/mod.rs | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index a955f88164c..e5444843516 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -112,32 +112,6 @@ //! }); //! rx.recv().unwrap(); //! ``` -//! -//! This second example is more costly since it allocates a new timer every -//! time a message is received, but it allows you to timeout after the channel -//! has been inactive for 5 seconds: -//! -//! ```no_run -//! # #![feature(std_misc, old_io)] -//! use std::sync::mpsc::channel; -//! use std::old_io::timer::Timer; -//! use std::time::Duration; -//! -//! let (tx, rx) = channel::(); -//! let mut timer = Timer::new().unwrap(); -//! -//! loop { -//! let timeout = timer.oneshot(Duration::seconds(5)); -//! -//! select! { -//! val = rx.recv() => println!("Received {}", val.unwrap()), -//! _ = timeout.recv() => { -//! println!("timed out, no message received in 5 seconds"); -//! break; -//! } -//! } -//! } -//! ``` #![stable(feature = "rust1", since = "1.0.0")]