File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -478,6 +478,25 @@ pub fn park_timeout_ms(ms: u32) {
478
478
///
479
479
/// Platforms which do not support nanosecond precision for sleeping will have
480
480
/// `dur` rounded up to the nearest granularity of time they can sleep for.
481
+ ///
482
+ /// # Example
483
+ ///
484
+ /// Waiting for the complete expiration of the timeout:
485
+ ///
486
+ /// ```rust,no_run
487
+ /// use std::thread::park_timeout;
488
+ /// use std::time::{Instant, Duration};
489
+ ///
490
+ /// let timeout = Duration::from_secs(2);
491
+ /// let beginning_park = Instant::now();
492
+ /// park_timeout(timeout);
493
+ ///
494
+ /// while beginning_park.elapsed() < timeout {
495
+ /// println!("restarting park_timeout after {:?}", beginning_park.elapsed());
496
+ /// let timeout = timeout - beginning_park.elapsed();
497
+ /// park_timeout(timeout);
498
+ /// }
499
+ /// ```
481
500
#[ stable( feature = "park_timeout" , since = "1.4.0" ) ]
482
501
pub fn park_timeout ( dur : Duration ) {
483
502
let thread = current ( ) ;
You can’t perform that action at this time.
0 commit comments