]> git.lizzy.rs Git - rust.git/commitdiff
Add example for `std::thread::sleep`.
authorCorey Farwell <coreyf@rwell.org>
Wed, 22 Jun 2016 01:41:02 +0000 (21:41 -0400)
committerCorey Farwell <coreyf@rwell.org>
Mon, 27 Jun 2016 17:06:20 +0000 (13:06 -0400)
src/libstd/thread/mod.rs

index c474aa60b3ee4e2b098c13cae7f0290a091d7361..a5a1b03f9f9026473a7cda078917d3e06fd0c490 100644 (file)
@@ -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)