[][src]Struct async_io::parking::Parker

pub struct Parker { /* fields omitted */ }

Waits for a notification.

Implementations

impl Parker[src]

pub fn new() -> Parker[src]

Creates a new parker.

Examples

use async_io::parking::Parker;

let p = Parker::new();

pub fn park(&self)[src]

Blocks until notified and then goes back into unnotified state.

Examples

use async_io::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();

pub fn park_timeout(&self, timeout: Duration) -> bool[src]

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

Returns true if notified before the timeout.

Examples

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

let p = Parker::new();

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

pub fn park_deadline(&self, deadline: Instant) -> bool[src]

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

Returns true if notified before the deadline.

Examples

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

let p = Parker::new();

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

pub fn unpark(&self)[src]

Notifies the parker.

Examples

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

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

thread::spawn(move || {
    thread::sleep(Duration::from_millis(500));
    u.unpark();
});

// Wakes up when `u.unpark()` notifies and then goes back into unnotified state.
p.park();

pub fn unparker(&self) -> Unparker[src]

Returns a handle for unparking.

The returned Unparker can be cloned and shared among threads.

Examples

use async_io::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

impl Debug for Parker[src]

impl Default for Parker[src]

impl Drop for Parker[src]

impl RefUnwindSafe for Parker[src]

impl UnwindSafe for Parker[src]

Auto Trait Implementations

impl Send for Parker

impl Sync for Parker

impl Unpin for Parker

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.