File tree 1 file changed +0
-26
lines changed
1 file changed +0
-26
lines changed Original file line number Diff line number Diff line change 113
113
//! rx.recv().unwrap();
114
114
//! ```
115
115
//!
116
- //! Reading from a channel with a timeout requires to use a Timer together
117
- //! with the channel. You can use the `select!` macro to select either and
118
- //! handle the timeout case. This first example will break out of the loop
119
- //! after 10 seconds no matter what:
120
- //!
121
- //! ```no_run
122
- //! # #![feature(std_misc, old_io)]
123
- //! use std::sync::mpsc::channel;
124
- //! use std::old_io::timer::Timer;
125
- //! use std::time::Duration;
126
- //!
127
- //! let (tx, rx) = channel::<i32>();
128
- //! let mut timer = Timer::new().unwrap();
129
- //! let timeout = timer.oneshot(Duration::seconds(10));
130
- //!
131
- //! loop {
132
- //! select! {
133
- //! val = rx.recv() => println!("Received {}", val.unwrap()),
134
- //! _ = timeout.recv() => {
135
- //! println!("timed out, total time was more than 10 seconds");
136
- //! break;
137
- //! }
138
- //! }
139
- //! }
140
- //! ```
141
- //!
142
116
//! This second example is more costly since it allocates a new timer every
143
117
//! time a message is received, but it allows you to timeout after the channel
144
118
//! has been inactive for 5 seconds:
You can’t perform that action at this time.
0 commit comments