Skip to content

Commit dfbf619

Browse files
Rollup merge of rust-lang#34406 - frewsxcv:sleep-ex, r=GuillaumeGomez
Add example for `std::thread::sleep`. None
2 parents 6b949e9 + bbc33ac commit dfbf619

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
@@ -379,6 +379,19 @@ pub fn sleep_ms(ms: u32) {
379379
/// signal being received or a spurious wakeup. Platforms which do not support
380380
/// nanosecond precision for sleeping will have `dur` rounded up to the nearest
381381
/// granularity of time they can sleep for.
382+
///
383+
/// # Examples
384+
///
385+
/// ```
386+
/// use std::{thread, time};
387+
///
388+
/// let ten_millis = time::Duration::from_millis(10);
389+
/// let now = time::Instant::now();
390+
///
391+
/// thread::sleep(ten_millis);
392+
///
393+
/// assert!(now.elapsed() >= ten_millis);
394+
/// ```
382395
#[stable(feature = "thread_sleep", since = "1.4.0")]
383396
pub fn sleep(dur: Duration) {
384397
imp::Thread::sleep(dur)

0 commit comments

Comments
 (0)