Skip to content

Commit 71a97c0

Browse files
authored
Rollup merge of rust-lang#34406 - frewsxcv:sleep-ex, r=alexcrichton
Add example for `std::thread::sleep`. None
2 parents a43574d + a7b9e54 commit 71a97c0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libstd/thread/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,19 @@ pub fn sleep_ms(ms: u32) {
394394
/// signal being received or a spurious wakeup. Platforms which do not support
395395
/// nanosecond precision for sleeping will have `dur` rounded up to the nearest
396396
/// granularity of time they can sleep for.
397+
///
398+
/// # Examples
399+
///
400+
/// ```rust,no_run
401+
/// use std::{thread, time};
402+
///
403+
/// let ten_millis = time::Duration::from_millis(10);
404+
/// let now = time::Instant::now();
405+
///
406+
/// thread::sleep(ten_millis);
407+
///
408+
/// assert!(now.elapsed() >= ten_millis);
409+
/// ```
397410
#[stable(feature = "thread_sleep", since = "1.4.0")]
398411
pub fn sleep(dur: Duration) {
399412
imp::Thread::sleep(dur)

0 commit comments

Comments
 (0)