std::rt: Add a standalone sleep function.
This commit is contained in:
parent
c7657b782e
commit
f39ab75a78
1 changed files with 14 additions and 0 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue