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 112
112
//! });
113
113
//! rx.recv().unwrap();
114
114
//! ```
115
- //!
116
- //! This second example is more costly since it allocates a new timer every
117
- //! time a message is received, but it allows you to timeout after the channel
118
- //! has been inactive for 5 seconds:
119
- //!
120
- //! ```no_run
121
- //! # #![feature(std_misc, old_io)]
122
- //! use std::sync::mpsc::channel;
123
- //! use std::old_io::timer::Timer;
124
- //! use std::time::Duration;
125
- //!
126
- //! let (tx, rx) = channel::<i32>();
127
- //! let mut timer = Timer::new().unwrap();
128
- //!
129
- //! loop {
130
- //! let timeout = timer.oneshot(Duration::seconds(5));
131
- //!
132
- //! select! {
133
- //! val = rx.recv() => println!("Received {}", val.unwrap()),
134
- //! _ = timeout.recv() => {
135
- //! println!("timed out, no message received in 5 seconds");
136
- //! break;
137
- //! }
138
- //! }
139
- //! }
140
- //! ```
141
115
142
116
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
143
117
You can’t perform that action at this time.
0 commit comments