diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-12 20:36:31 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-17 09:34:42 -0700 |
| commit | 04cf5344111c357ad80335b88709281bb4bfaa0a (patch) | |
| tree | 2a0788a1caed1c284a74330305cbf2aceebd5387 /src/libstd/thread.rs | |
| parent | 970baad714d4119e5f93647163f197c9474d6ace (diff) | |
| download | rust-04cf5344111c357ad80335b88709281bb4bfaa0a.tar.gz rust-04cf5344111c357ad80335b88709281bb4bfaa0a.zip | |
std: Implement `thread::sleep`
This function is the current replacement for `std::old_io::timer` which will soon be deprecated. This function is unstable and has its own feature gate as it does not yet have an RFC nor has it existed for very long.
Diffstat (limited to 'src/libstd/thread.rs')
| -rw-r--r-- | src/libstd/thread.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index adc3b77407a..0216f324fdb 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -379,6 +379,19 @@ pub fn panicking() -> bool { unwind::panicking() } +/// Put the current thread to sleep for the specified amount of time. +/// +/// The thread may sleep longer than the duration specified due to scheduling +/// specifics or platform-dependent functionality. Note that on unix platforms +/// this function will not return early due to a signal being received or a +/// spurious wakeup. +#[unstable(feature = "thread_sleep", + reason = "recently added, needs an RFC, and `Duration` itself is \ + unstable")] +pub fn sleep(dur: Duration) { + imp::sleep(dur) +} + /// Block unless or until the current thread's token is made available (may wake spuriously). /// /// See the module doc for more detail. @@ -935,6 +948,12 @@ mod test { } } + #[test] + fn sleep_smoke() { + thread::sleep(Duration::milliseconds(2)); + thread::sleep(Duration::milliseconds(-2)); + } + // NOTE: the corresponding test for stderr is in run-pass/task-stderr, due // to the test harness apparently interfering with stderr configuration. } |
