Add an example to std:🧵:park_timeout
This commit is contained in:
parent
ea07d52676
commit
4fc6f5ac26
1 changed files with 19 additions and 0 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue