about summary refs log tree commit diff
path: root/src/libstd/thread.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-03-17 17:15:54 +0000
committerbors <bors@rust-lang.org>2015-03-17 17:15:54 +0000
commitbfac337daab9b86971bcb3db61382ac44f94621c (patch)
tree34bc72817ddffae38dde0fa30b8f35a0bc92e1d3 /src/libstd/thread.rs
parentc64d671671aea2e44ee7fc6eb00ee75fc30ed7b9 (diff)
parent04cf5344111c357ad80335b88709281bb4bfaa0a (diff)
downloadrust-bfac337daab9b86971bcb3db61382ac44f94621c.tar.gz
rust-bfac337daab9b86971bcb3db61382ac44f94621c.zip
Auto merge of #23330 - alexcrichton:thread-sleep, r=aturon
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.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs
index a40b26c85be..d2742d4b45a 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.
 }