Capture elapsed duration in Thread::park_timeout example
This commit is contained in:
parent
29ef41215c
commit
0389d40ce0
@ -787,12 +787,16 @@ pub fn park_timeout_ms(ms: u32) {
|
||||
///
|
||||
/// 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);
|
||||
/// let mut timeout_remaining = timeout;
|
||||
/// loop {
|
||||
/// park_timeout(timeout_remaining);
|
||||
/// let elapsed = beginning_park.elapsed();
|
||||
/// if elapsed >= timeout {
|
||||
/// break;
|
||||
/// }
|
||||
/// println!("restarting park_timeout after {:?}", elapsed);
|
||||
/// timeout_remaining = timeout - elapsed;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user