Skip to content

Commit 5c4f65e

Browse files
committed
auto merge of rust-lang#9191 : huonw/rust/are-you-tired, r=cmr
Allows `std::rt::io::timer::sleep(1000)` rather than `std::rt::io::timer::Timer::new().unwrap().sleep(1000)`.
2 parents 524c190 + f39ab75 commit 5c4f65e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libstd/rt/io/timer.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ use rt::local::Local;
1717

1818
pub struct Timer(~RtioTimerObject);
1919

20+
/// Sleep the current task for `msecs` milliseconds.
21+
pub fn sleep(msecs: u64) {
22+
let mut timer = Timer::new().expect("timer::sleep: could not create a Timer");
23+
24+
timer.sleep(msecs)
25+
}
26+
2027
impl Timer {
2128

2229
pub fn new() -> Option<Timer> {
@@ -52,4 +59,11 @@ mod test {
5259
do timer.map_move |mut t| { t.sleep(1) };
5360
}
5461
}
62+
63+
#[test]
64+
fn test_io_timer_sleep_standalone() {
65+
do run_in_mt_newsched_task {
66+
sleep(1)
67+
}
68+
}
5569
}

0 commit comments

Comments
 (0)