Skip to content

Commit f39ab75

Browse files
committed
std::rt: Add a standalone sleep function.
1 parent c7657b7 commit f39ab75

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)