pub struct Condvar { /* private fields */ }
Expand description
A condition variable. Condition variables allow for tasks to wait until a notification is received.
§Examples
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = pair.clone();
spawn(async move {
let (lock, cvar) = &*pair2;
let mut started = lock.lock().await;
*started = true;
cvar.notify_one();
}).detach();
let (lock, cvar) = &*pair;
let mut started = lock.lock().await;
while !*started {
started = cvar.wait(started).await;
}
Implementations§
Source§impl Condvar
impl Condvar
Sourcepub fn wait<'a, T>(
&'a self,
guard: MutexGuard<'a, T>,
) -> CondvarWaitFuture<'a, T> ⓘ
pub fn wait<'a, T>( &'a self, guard: MutexGuard<'a, T>, ) -> CondvarWaitFuture<'a, T> ⓘ
Waits for a notification on the condition variable.
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Notify one task waiting on the condition variable.
Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Notify all tasks waiting on the condition variable.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Condvar
impl RefUnwindSafe for Condvar
impl Send for Condvar
impl Sync for Condvar
impl Unpin for Condvar
impl UnwindSafe for Condvar
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