Parker

Struct Parker 

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

Waits for a notification.

Implementations§

Source§

impl Parker

Source

pub fn new() -> Parker

Creates a new parker.

§Examples
use parking::Parker;

let p = Parker::new();
Source

pub fn park(&self)

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();
Source

pub fn park_timeout(&self, duration: Duration) -> bool

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));
Source

pub fn park_deadline(&self, instant: Instant) -> bool

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));
Source

pub fn unpark(&self) -> bool

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();
Source

pub fn unparker(&self) -> Unparker

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§

Source§

impl Debug for Parker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Parker

Source§

fn default() -> Parker

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

Auto Trait Implementations§

§

impl Freeze for Parker

§

impl !RefUnwindSafe for Parker

§

impl Send for Parker

§

impl !Sync for Parker

§

impl Unpin for Parker

§

impl UnwindSafe for Parker

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 8 bytes