parking

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.