diff options
| author | Stefan Schindler <dns2utf8@estada.ch> | 2016-08-03 13:30:28 +0200 |
|---|---|---|
| committer | Stefan Schindler <dns2utf8@estada.ch> | 2016-08-03 23:12:25 +0200 |
| commit | 4fc6f5ac264a58ddaaaf3d2ddfbe011eb675edaf (patch) | |
| tree | 3083e714667a33c19602bdf3e50cd6b1813325de /src/libstd/thread | |
| parent | ea07d52676a68aff3e85599469523a25eeb1afbf (diff) | |
| download | rust-4fc6f5ac264a58ddaaaf3d2ddfbe011eb675edaf.tar.gz rust-4fc6f5ac264a58ddaaaf3d2ddfbe011eb675edaf.zip | |
Add an example to `std::thread::park_timeout`
Diffstat (limited to 'src/libstd/thread')
| -rw-r--r-- | src/libstd/thread/mod.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index e9736fea7b3..40d5c700246 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -478,6 +478,25 @@ pub fn park_timeout_ms(ms: u32) { /// /// Platforms which do not support nanosecond precision for sleeping will have /// `dur` rounded up to the nearest granularity of time they can sleep for. +/// +/// # Example +/// +/// Waiting for the complete expiration of the timeout: +/// +/// ```rust,no_run +/// use std::thread::park_timeout; +/// use std::time::{Instant, Duration}; +/// +/// let timeout = Duration::from_secs(2); +/// let beginning_park = Instant::now(); +/// park_timeout(timeout); +/// +/// while beginning_park.elapsed() < timeout { +/// println!("restarting park_timeout after {:?}", beginning_park.elapsed()); +/// let timeout = timeout - beginning_park.elapsed(); +/// park_timeout(timeout); +/// } +/// ``` #[stable(feature = "park_timeout", since = "1.4.0")] pub fn park_timeout(dur: Duration) { let thread = current(); |
