From f39ab75a782a89f5e2bdf85c5fedc7991094ec72 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sun, 15 Sep 2013 00:00:13 +1000 Subject: [PATCH] std::rt: Add a standalone sleep function. --- src/libstd/rt/io/timer.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libstd/rt/io/timer.rs b/src/libstd/rt/io/timer.rs index 6754511b03811..53e4c4051e1c3 100644 --- a/src/libstd/rt/io/timer.rs +++ b/src/libstd/rt/io/timer.rs @@ -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 { @@ -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) + } + } }