Skip to content

Commit 9da130a

Browse files
committed
---
yaml --- r: 127870 b: refs/heads/auto c: 1666dab h: refs/heads/master v: v3
1 parent b933db4 commit 9da130a

File tree

2 files changed

+50
-173
lines changed

2 files changed

+50
-173
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 51e9728292ec4b89de095e2f0c2e92aa60927a88
16+
refs/heads/auto: 1666dabcbc2628fb4a5e4b9c43a13fd1179112b2
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libstd/io/timer.rs

Lines changed: 49 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,10 @@ fn in_ms(d: Duration) -> u64 {
7979

8080
/// Sleep the current task for the specified duration.
8181
pub fn sleep(duration: Duration) {
82-
sleep_ms(in_ms(duration))
83-
}
84-
85-
/// Sleep the current task for `msecs` milliseconds.
86-
pub fn sleep_ms(msecs: u64) {
8782
let timer = Timer::new();
8883
let mut timer = timer.ok().expect("timer::sleep: could not create a Timer");
8984

90-
timer.sleep_ms(msecs)
85+
timer.sleep(duration)
9186
}
9287

9388
impl Timer {
@@ -108,14 +103,6 @@ impl Timer {
108103
self.obj.sleep(in_ms(duration));
109104
}
110105

111-
/// Blocks the current task for `msecs` milliseconds.
112-
///
113-
/// Note that this function will cause any other receivers for this timer to
114-
/// be invalidated (the other end will be closed).
115-
pub fn sleep_ms(&mut self, msecs: u64) {
116-
self.obj.sleep(msecs);
117-
}
118-
119106
/// Creates a oneshot receiver which will have a notification sent when
120107
/// the specified duration has elapsed.
121108
///
@@ -133,46 +120,6 @@ impl Timer {
133120
return rx
134121
}
135122

136-
/// Creates a oneshot receiver which will have a notification sent when
137-
/// `msecs` milliseconds has elapsed.
138-
///
139-
/// This does *not* block the current task, but instead returns immediately.
140-
///
141-
/// Note that this invalidates any previous receiver which has been created
142-
/// by this timer, and that the returned receiver will be invalidated once
143-
/// the timer is destroyed (when it falls out of scope). In particular, if
144-
/// this is called in method-chaining style, the receiver will be
145-
/// invalidated at the end of that statement, and all `recv` calls will
146-
/// fail.
147-
///
148-
/// # Example
149-
///
150-
/// ```rust
151-
/// use std::io::Timer;
152-
///
153-
/// let mut timer = Timer::new().unwrap();
154-
/// let ten_milliseconds = timer.oneshot(10);
155-
///
156-
/// for _ in range(0u, 100) { /* do work */ }
157-
///
158-
/// // blocks until 10 ms after the `oneshot` call
159-
/// ten_milliseconds.recv();
160-
/// ```
161-
///
162-
/// ```rust
163-
/// use std::io::Timer;
164-
///
165-
/// // Incorrect, method chaining-style:
166-
/// let mut five_ms = Timer::new().unwrap().oneshot(5);
167-
/// // The timer object was destroyed, so this will always fail:
168-
/// // five_ms.recv()
169-
/// ```
170-
pub fn oneshot_ms(&mut self, msecs: u64) -> Receiver<()> {
171-
let (tx, rx) = channel();
172-
self.obj.oneshot(msecs, box TimerCallback { tx: tx });
173-
return rx
174-
}
175-
176123
/// Creates a receiver which will have a continuous stream of notifications
177124
/// being sent each time the specified duration has elapsed.
178125
///
@@ -191,54 +138,6 @@ impl Timer {
191138
self.obj.period(in_ms(duration), box TimerCallback { tx: tx });
192139
return rx
193140
}
194-
195-
/// Creates a receiver which will have a continuous stream of notifications
196-
/// being sent every `msecs` milliseconds.
197-
///
198-
/// This does *not* block the current task, but instead returns
199-
/// immediately. The first notification will not be received immediately,
200-
/// but rather after `msec` milliseconds have passed.
201-
///
202-
/// Note that this invalidates any previous receiver which has been created
203-
/// by this timer, and that the returned receiver will be invalidated once
204-
/// the timer is destroyed (when it falls out of scope). In particular, if
205-
/// this is called in method-chaining style, the receiver will be
206-
/// invalidated at the end of that statement, and all `recv` calls will
207-
/// fail.
208-
///
209-
/// # Example
210-
///
211-
/// ```rust
212-
/// use std::io::Timer;
213-
///
214-
/// let mut timer = Timer::new().unwrap();
215-
/// let ten_milliseconds = timer.periodic(10);
216-
///
217-
/// for _ in range(0u, 100) { /* do work */ }
218-
///
219-
/// // blocks until 10 ms after the `periodic` call
220-
/// ten_milliseconds.recv();
221-
///
222-
/// for _ in range(0u, 100) { /* do work */ }
223-
///
224-
/// // blocks until 20 ms after the `periodic` call (*not* 10ms after the
225-
/// // previous `recv`)
226-
/// ten_milliseconds.recv();
227-
/// ```
228-
///
229-
/// ```rust
230-
/// use std::io::Timer;
231-
///
232-
/// // Incorrect, method chaining-style.
233-
/// let mut five_ms = Timer::new().unwrap().periodic(5);
234-
/// // The timer object was destroyed, so this will always fail:
235-
/// // five_ms.recv()
236-
/// ```
237-
pub fn periodic_ms(&mut self, msecs: u64) -> Receiver<()> {
238-
let (tx, rx) = channel();
239-
self.obj.period(msecs, box TimerCallback { tx: tx });
240-
return rx
241-
}
242141
}
243142

244143
impl Callback for TimerCallback {
@@ -249,101 +148,103 @@ impl Callback for TimerCallback {
249148

250149
#[cfg(test)]
251150
mod test {
252-
iotest!(fn test_io_timer_sleep_ms_simple() {
151+
use time::Duration;
152+
153+
iotest!(fn test_io_timer_sleep_simple() {
253154
let mut timer = Timer::new().unwrap();
254-
timer.sleep_ms(1);
155+
timer.sleep(Duration::milliseconds(1));
255156
})
256157

257-
iotest!(fn test_io_timer_sleep_oneshot_ms() {
158+
iotest!(fn test_io_timer_sleep_oneshot() {
258159
let mut timer = Timer::new().unwrap();
259-
timer.oneshot_ms(1).recv();
160+
timer.oneshot(Duration::milliseconds(1)).recv();
260161
})
261162

262-
iotest!(fn test_io_timer_sleep_oneshot_ms_forget() {
163+
iotest!(fn test_io_timer_sleep_oneshot_forget() {
263164
let mut timer = Timer::new().unwrap();
264-
timer.oneshot_ms(100000000000);
165+
timer.oneshot(Duration::milliseconds(100000000000));
265166
})
266167

267-
iotest!(fn oneshot_ms_twice() {
168+
iotest!(fn oneshot_twice() {
268169
let mut timer = Timer::new().unwrap();
269-
let rx1 = timer.oneshot_ms(10000);
270-
let rx = timer.oneshot_ms(1);
170+
let rx1 = timer.oneshot(Duration::milliseconds(10000));
171+
let rx = timer.oneshot(1);
271172
rx.recv();
272173
assert_eq!(rx1.recv_opt(), Err(()));
273174
})
274175

275-
iotest!(fn test_io_timer_oneshot_ms_then_sleep() {
176+
iotest!(fn test_io_timer_oneshot_then_sleep() {
276177
let mut timer = Timer::new().unwrap();
277-
let rx = timer.oneshot_ms(100000000000);
278-
timer.sleep_ms(1); // this should invalidate rx
178+
let rx = timer.oneshot(Duration::milliseconds(100000000000));
179+
timer.sleep(Duration::milliseconds(1)); // this should invalidate rx
279180

280181
assert_eq!(rx.recv_opt(), Err(()));
281182
})
282183

283-
iotest!(fn test_io_timer_sleep_periodic_ms() {
184+
iotest!(fn test_io_timer_sleep_periodic() {
284185
let mut timer = Timer::new().unwrap();
285-
let rx = timer.periodic_ms(1);
186+
let rx = timer.periodic(Duration::milliseconds(1));
286187
rx.recv();
287188
rx.recv();
288189
rx.recv();
289190
})
290191

291-
iotest!(fn test_io_timer_sleep_periodic_ms_forget() {
192+
iotest!(fn test_io_timer_sleep_periodic_forget() {
292193
let mut timer = Timer::new().unwrap();
293-
timer.periodic_ms(100000000000);
194+
timer.periodic(Duration::milliseconds(100000000000));
294195
})
295196

296-
iotest!(fn test_io_timer_sleep_ms_standalone() {
297-
sleep_ms(1)
197+
iotest!(fn test_io_timer_sleep_standalone() {
198+
sleep(Duration::milliseconds(1))
298199
})
299200

300-
iotest!(fn oneshot_ms() {
201+
iotest!(fn oneshot() {
301202
let mut timer = Timer::new().unwrap();
302203

303-
let rx = timer.oneshot_ms(1);
204+
let rx = timer.oneshot(Duration::milliseconds(1));
304205
rx.recv();
305206
assert!(rx.recv_opt().is_err());
306207

307-
let rx = timer.oneshot_ms(1);
208+
let rx = timer.oneshot(Duration::milliseconds(1));
308209
rx.recv();
309210
assert!(rx.recv_opt().is_err());
310211
})
311212

312213
iotest!(fn override() {
313214
let mut timer = Timer::new().unwrap();
314-
let orx = timer.oneshot_ms(100);
315-
let prx = timer.periodic_ms(100);
316-
timer.sleep_ms(1);
215+
let orx = timer.oneshot(Duration::milliseconds(100));
216+
let prx = timer.periodic(Duration::milliseconds(100));
217+
timer.sleep(Duration::milliseconds(1));
317218
assert_eq!(orx.recv_opt(), Err(()));
318219
assert_eq!(prx.recv_opt(), Err(()));
319-
timer.oneshot_ms(1).recv();
220+
timer.oneshot(Duration::milliseconds(1)).recv();
320221
})
321222

322-
iotest!(fn period_ms() {
223+
iotest!(fn period() {
323224
let mut timer = Timer::new().unwrap();
324-
let rx = timer.periodic_ms(1);
225+
let rx = timer.periodic(Duration::milliseconds(1));
325226
rx.recv();
326227
rx.recv();
327-
let rx2 = timer.periodic_ms(1);
228+
let rx2 = timer.periodic(Durtion::milliseconds(1));
328229
rx2.recv();
329230
rx2.recv();
330231
})
331232

332-
iotest!(fn sleep_ms() {
233+
iotest!(fn sleep() {
333234
let mut timer = Timer::new().unwrap();
334-
timer.sleep_ms(1);
335-
timer.sleep_ms(1);
235+
timer.sleep(Duration::milliseconds(1));
236+
timer.sleep(Duration::milliseconds(1));
336237
})
337238

338-
iotest!(fn oneshot_ms_fail() {
239+
iotest!(fn oneshot_fail() {
339240
let mut timer = Timer::new().unwrap();
340-
let _rx = timer.oneshot_ms(1);
241+
let _rx = timer.oneshot(Duration::milliseconds(1));
341242
fail!();
342243
} #[should_fail])
343244

344-
iotest!(fn period_ms_fail() {
245+
iotest!(fn period_fail() {
345246
let mut timer = Timer::new().unwrap();
346-
let _rx = timer.periodic_ms(1);
247+
let _rx = timer.periodic(Duration::milliseconds(1));
347248
fail!();
348249
} #[should_fail])
349250

@@ -355,7 +256,7 @@ mod test {
355256
iotest!(fn closing_channel_during_drop_doesnt_kill_everything() {
356257
// see issue #10375
357258
let mut timer = Timer::new().unwrap();
358-
let timer_rx = timer.periodic_ms(1000);
259+
let timer_rx = timer.periodic(Duration::milliseconds(1000));
359260

360261
spawn(proc() {
361262
let _ = timer_rx.recv_opt();
@@ -368,82 +269,58 @@ mod test {
368269
iotest!(fn reset_doesnt_switch_tasks() {
369270
// similar test to the one above.
370271
let mut timer = Timer::new().unwrap();
371-
let timer_rx = timer.periodic_ms(1000);
272+
let timer_rx = timer.periodic(Duration::milliseconds(1000));
372273

373274
spawn(proc() {
374275
let _ = timer_rx.recv_opt();
375276
});
376277

377-
timer.oneshot_ms(1);
278+
timer.oneshot(Duration::milliseconds(1));
378279
})
379280

380281
iotest!(fn reset_doesnt_switch_tasks2() {
381282
// similar test to the one above.
382283
let mut timer = Timer::new().unwrap();
383-
let timer_rx = timer.periodic_ms(1000);
284+
let timer_rx = timer.periodic(Duration::milliseconds(1000));
384285

385286
spawn(proc() {
386287
let _ = timer_rx.recv_opt();
387288
});
388289

389-
timer.sleep_ms(1);
290+
timer.sleep(Duration::milliseconds(1));
390291
})
391292

392293
iotest!(fn sender_goes_away_oneshot() {
393294
let rx = {
394295
let mut timer = Timer::new().unwrap();
395-
timer.oneshot_ms(1000)
296+
timer.oneshot(Duration::milliseconds(1000))
396297
};
397298
assert_eq!(rx.recv_opt(), Err(()));
398299
})
399300

400301
iotest!(fn sender_goes_away_period() {
401302
let rx = {
402303
let mut timer = Timer::new().unwrap();
403-
timer.periodic_ms(1000)
304+
timer.periodic(Duration::milliseconds(1000))
404305
};
405306
assert_eq!(rx.recv_opt(), Err(()));
406307
})
407308

408309
iotest!(fn receiver_goes_away_oneshot() {
409310
let mut timer1 = Timer::new().unwrap();
410-
timer1.oneshot_ms(1);
311+
timer1.oneshot(Duration::milliseconds(1));
411312
let mut timer2 = Timer::new().unwrap();
412313
// while sleeping, the previous timer should fire and not have its
413314
// callback do something terrible.
414-
timer2.sleep_ms(2);
315+
timer2.sleep(Duration::milliseconds(2));
415316
})
416317

417318
iotest!(fn receiver_goes_away_period() {
418319
let mut timer1 = Timer::new().unwrap();
419-
timer1.periodic_ms(1);
320+
timer1.periodic(Duration::milliseconds(1));
420321
let mut timer2 = Timer::new().unwrap();
421322
// while sleeping, the previous timer should fire and not have its
422323
// callback do something terrible.
423-
timer2.sleep_ms(2);
424-
})
425-
426-
427-
iotest!(fn test_io_timer_sleep_duration_simple() {
428-
use time::Duration;
429-
let mut timer = Timer::new().unwrap();
430-
timer.sleep(Duration::seconds(1));
431-
})
432-
433-
iotest!(fn test_io_timer_sleep_oneshot_duration() {
434-
use time::Duration;
435-
let mut timer = Timer::new().unwrap();
436-
timer.oneshot(Duration::seconds(1)).recv();
324+
timer2.sleep(Duration::milliseconds(2));
437325
})
438-
439-
iotest!(fn test_io_timer_sleep_periodic_duration() {
440-
use time::Duration;
441-
let mut timer = Timer::new().unwrap();
442-
let rx = timer.periodic(Duration::seconds(1));
443-
rx.recv();
444-
rx.recv();
445-
rx.recv();
446-
})
447-
448-
449326
}

0 commit comments

Comments
 (0)