about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-09-14 14:05:51 -0700
committerbors <bors@rust-lang.org>2013-09-14 14:05:51 -0700
commit5c4f65e6f593ed790a9d6328c9ff0093572e87ef (patch)
treeb802536962d386f6188b5fb9bf4375725afe9eb1 /src/libstd
parent524c190565c0dbafdb7f27bc3c27c0952f32c2f9 (diff)
parentf39ab75a782a89f5e2bdf85c5fedc7991094ec72 (diff)
downloadrust-5c4f65e6f593ed790a9d6328c9ff0093572e87ef.tar.gz
rust-5c4f65e6f593ed790a9d6328c9ff0093572e87ef.zip
auto merge of #9191 : huonw/rust/are-you-tired, r=cmr
Allows `std::rt::io::timer::sleep(1000)` rather than `std::rt::io::timer::Timer::new().unwrap().sleep(1000)`.
Diffstat (limited to 'src/libstd')
-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)
+        }
+    }
 }