pub struct Parker { /* private fields */ }
Expand description
Waits for a notification.
Implementations§
Source§impl Parker
impl Parker
Sourcepub fn park(&self)
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();
Sourcepub fn park_timeout(&self, duration: Duration) -> bool
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));
Sourcepub fn park_deadline(&self, instant: Instant) -> bool
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));
Sourcepub fn unpark(&self) -> bool
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();
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more