@@ -114,6 +114,29 @@ impl Timer {
114
114
/// this is called in method-chaining style, the receiver will be
115
115
/// invalidated at the end of that statement, and all `recv` calls will
116
116
/// fail.
117
+ ///
118
+ /// # Example
119
+ ///
120
+ /// ```rust
121
+ /// use std::io::Timer;
122
+ ///
123
+ /// let mut timer = Timer::new().unwrap();
124
+ /// let ten_milliseconds = timer.oneshot(10);
125
+ ///
126
+ /// for _ in range(0u, 100) { /* do work */ }
127
+ ///
128
+ /// // blocks until 10 ms after the `oneshot` call
129
+ /// ten_milliseconds.recv();
130
+ /// ```
131
+ ///
132
+ /// ```rust
133
+ /// use std::io::Timer;
134
+ ///
135
+ /// // Incorrect, method chaining-style:
136
+ /// let mut five_ms = Timer::new().unwrap().oneshot(5);
137
+ /// // The timer object was destroyed, so this will always fail:
138
+ /// // five_ms.recv()
139
+ /// ```
117
140
pub fn oneshot ( & mut self , duration : Duration ) -> Receiver < ( ) > {
118
141
let ( tx, rx) = channel ( ) ;
119
142
self . obj . oneshot ( in_ms ( duration) , box TimerCallback { tx : tx } ) ;
@@ -133,6 +156,35 @@ impl Timer {
133
156
/// this is called in method-chaining style, the receiver will be
134
157
/// invalidated at the end of that statement, and all `recv` calls will
135
158
/// fail.
159
+ ///
160
+ /// # Example
161
+ ///
162
+ /// ```rust
163
+ /// use std::io::Timer;
164
+ ///
165
+ /// let mut timer = Timer::new().unwrap();
166
+ /// let ten_milliseconds = timer.periodic(10);
167
+ ///
168
+ /// for _ in range(0u, 100) { /* do work */ }
169
+ ///
170
+ /// // blocks until 10 ms after the `periodic` call
171
+ /// ten_milliseconds.recv();
172
+ ///
173
+ /// for _ in range(0u, 100) { /* do work */ }
174
+ ///
175
+ /// // blocks until 20 ms after the `periodic` call (*not* 10ms after the
176
+ /// // previous `recv`)
177
+ /// ten_milliseconds.recv();
178
+ /// ```
179
+ ///
180
+ /// ```rust
181
+ /// use std::io::Timer;
182
+ ///
183
+ /// // Incorrect, method chaining-style.
184
+ /// let mut five_ms = Timer::new().unwrap().periodic(5);
185
+ /// // The timer object was destroyed, so this will always fail:
186
+ /// // five_ms.recv()
187
+ /// ```
136
188
pub fn periodic ( & mut self , duration : Duration ) -> Receiver < ( ) > {
137
189
let ( tx, rx) = channel ( ) ;
138
190
self . obj . period ( in_ms ( duration) , box TimerCallback { tx : tx } ) ;
0 commit comments