std::rt: Add a standalone sleep function.

This commit is contained in:
Huon Wilson 2013-09-15 00:00:13 +10:00
parent c7657b782e
commit f39ab75a78

View file

@ -17,6 +17,13 @@ use rt::local::Local;
pub struct Timer(~RtioTimerObject);
/// Sleep the current task for `msecs` milliseconds.
pub fn sleep(msecs: u64) {
let mut timer = Timer::new().expect("timer::sleep: could not create a Timer");
timer.sleep(msecs)
}
impl Timer {
pub fn new() -> Option<Timer> {
@ -52,4 +59,11 @@ mod test {
do timer.map_move |mut t| { t.sleep(1) };
}
}
#[test]
fn test_io_timer_sleep_standalone() {
do run_in_mt_newsched_task {
sleep(1)
}
}
}