pub struct Condvar { /* private fields */ }
Expand description
A condition variable.
This type allows multiple tasks to wait for an action to be completed.
This type is similar to [std::sync::Condvar
], except that it is
async and cross-platform, and cannot be spuriously woken.
§Examples
use no_std_async::{Condvar, Mutex};
static CONDVAR: Condvar = Condvar::new();
static VALUE: Mutex<u8> = Mutex::new(0);
async fn task1() {
for i in 0..10 {
*VALUE.lock().await += 1; // some work
}
CONDVAR.notify_one(); // we're done!
}
async fn task2() {
CONDVAR.wait().await; // wait for task1 to finish
assert_eq!(10, *VALUE.lock().await);
}
Implementations§
Source§impl Condvar
impl Condvar
Sourcepub async fn wait(&self)
pub async fn wait(&self)
Blocks the current task until this condition variable receives a notification.
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Notifies a single task waiting on this condition variable.
Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Notifies all tasks waiting on this condition variable.
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