From bbc33ac5050cc4e351f03f139a360efb0f2439ce Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 21 Jun 2016 21:41:02 -0400 Subject: [PATCH] Add example for `std::thread::sleep`. --- src/libstd/thread/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index c474aa60b3ee4..30c337ab7bc7b 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -379,6 +379,19 @@ pub fn sleep_ms(ms: u32) { /// signal being received or a spurious wakeup. Platforms which do not support /// nanosecond precision for sleeping will have `dur` rounded up to the nearest /// granularity of time they can sleep for. +/// +/// # Examples +/// +/// ``` +/// use std::{thread, time}; +/// +/// let ten_millis = time::Duration::from_millis(10); +/// let now = time::Instant::now(); +/// +/// thread::sleep(ten_millis); +/// +/// assert!(now.elapsed() >= ten_millis); +/// ``` #[stable(feature = "thread_sleep", since = "1.4.0")] pub fn sleep(dur: Duration) { imp::Thread::sleep(dur)