diff options
| author | bors <bors@rust-lang.org> | 2013-09-14 14:05:51 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-09-14 14:05:51 -0700 |
| commit | 5c4f65e6f593ed790a9d6328c9ff0093572e87ef (patch) | |
| tree | b802536962d386f6188b5fb9bf4375725afe9eb1 /src/libstd/rt | |
| parent | 524c190565c0dbafdb7f27bc3c27c0952f32c2f9 (diff) | |
| parent | f39ab75a782a89f5e2bdf85c5fedc7991094ec72 (diff) | |
| download | rust-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/rt')
| -rw-r--r-- | src/libstd/rt/io/timer.rs | 14 |
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) + } + } } |
