diff options
| author | Corey Farwell <coreyf@rwell.org> | 2016-06-21 21:41:02 -0400 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2016-06-27 13:06:20 -0400 |
| commit | a7b9e5441bed52ab89e0212816fdd09ea9a29d36 (patch) | |
| tree | f2858a7ee6f8dfeebe684a88dd0725fe47a89cc9 /src/libstd/thread/mod.rs | |
| parent | fe96928d7de991e527a7ed7b88bb30aa965c8a08 (diff) | |
| download | rust-a7b9e5441bed52ab89e0212816fdd09ea9a29d36.tar.gz rust-a7b9e5441bed52ab89e0212816fdd09ea9a29d36.zip | |
Add example for `std::thread::sleep`.
Diffstat (limited to 'src/libstd/thread/mod.rs')
| -rw-r--r-- | src/libstd/thread/mod.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index c474aa60b3e..a5a1b03f9f9 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 +/// +/// ```rust,no_run +/// 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) |
