std::thread::park_timeout - Rust
Description: API documentation for the Rust `park_timeout` fn in crate `std`.
Keywords: rust, rustlang, rust-lang, park_timeout

# 1.4.0[−][src]Function std::thread::park_timeout

    pub fn park_timeout(dur: Duration)

Blocks unless or until the current thread's token is made available or the specified duration has been reached (may wake spuriously).

The semantics of this function are equivalent to `park` except that the thread will be blocked for roughly no longer than `dur`. This method should not be used for precise timing due to anomalies such as preemption or platform differences that may not cause the maximum amount of time waited to be precisely `dur` long.

See the park documentation for more details.

# Platform-specific behavior

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

Waiting for the complete expiration of the timeout:

    use std::thread::park_timeout;
    use std::time::{Instant, Duration};

    let timeout = Duration::from_secs(2);
    let beginning_park = Instant::now();

    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;
    }Run

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)