Skip to content

Commit bbc33ac

Browse files
committed
Add example for std::thread::sleep.
1 parent fe96928 commit bbc33ac

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libstd/thread/mod.rs

+13
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)