pub struct Parker { /* private fields */ }
Expand description

Waits for a notification.

Implementations

Creates a new parker.

Examples
use parking::Parker;

let p = Parker::new();

Blocks until notified and then goes back into unnotified state.

Examples
use parking::Parker;

let p = Parker::new();
let u = p.unparker();

// Notify the parker.
u.unpark();

// Wakes up immediately because the parker is notified.
p.park();

Blocks until notified and then goes back into unnotified state, or times out after duration.

Returns true if notified before the timeout.

Examples
use std::time::Duration;
use parking::Parker;

let p = Parker::new();

// Wait for a notification, or time out after 500 ms.
p.park_timeout(Duration::from_millis(500));

Blocks until notified and then goes back into unnotified state, or times out at instant.

Returns true if notified before the deadline.

Examples
use std::time::{Duration, Instant};
use parking::Parker;

let p = Parker::new();

// Wait for a notification, or time out after 500 ms.
p.park_deadline(Instant::now() + Duration::from_millis(500));

Notifies the parker.

Returns true if this call is the first to notify the parker, or false if the parker was already notified.

Examples
use std::thread;
use std::time::Duration;
use parking::Parker;

let p = Parker::new();

assert_eq!(p.unpark(), true);
assert_eq!(p.unpark(), false);

// Wakes up immediately.
p.park();

Returns a handle for unparking.

The returned Unparker can be cloned and shared among threads.

Examples
use parking::Parker;

let p = Parker::new();
let u = p.unparker();

// Notify the parker.
u.unpark();

// Wakes up immediately because the parker is notified.
p.park();

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.