about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-09-15 00:00:13 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-09-15 00:20:48 +1000
commitf39ab75a782a89f5e2bdf85c5fedc7991094ec72 (patch)
tree6d4c5680c1b09e229bd949f7d9e3434043f40391 /src/libstd/rt
parentc7657b782e0249ead5b01efba3782cff0f065198 (diff)
downloadrust-f39ab75a782a89f5e2bdf85c5fedc7991094ec72.tar.gz
rust-f39ab75a782a89f5e2bdf85c5fedc7991094ec72.zip
std::rt: Add a standalone sleep function.
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/io/timer.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libstd/rt/io/timer.rs b/src/libstd/rt/io/timer.rs
index 6754511b038..53e4c4051e1 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<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)
+        }
+    }
 }