pub struct CondVar {
inner: Mutex<Wakers>,
}
Expand description
CondVar is an async version of https://doc.rust-lang.org/std/sync/struct.Condvar.html
§Example
use std::sync::Arc;
use karyon_core::async_util::CondVar;
use karyon_core::async_runtime::{spawn, lock::Mutex};
async {
let val = Arc::new(Mutex::new(false));
let condvar = Arc::new(CondVar::new());
spawn({
let val = val.clone();
let condvar = condvar.clone();
async move {
let mut val = val.lock().await;
// While the boolean flag is false, wait for a signal.
while !*val {
val = condvar.wait(val).await;
}
// ...
}
});
spawn({
let condvar = condvar.clone();
async move {
let mut val = val.lock().await;
// While the boolean flag is false, wait for a signal.
while !*val {
val = condvar.wait(val).await;
}
// ...
}
});
// Wake up all waiting tasks on this condvar
condvar.broadcast();
};
Fields§
§inner: Mutex<Wakers>
Implementations§
Source§impl CondVar
impl CondVar
Sourcepub async fn wait<'a, T>(&self, g: MutexGuard<'a, T>) -> MutexGuard<'a, T>
pub async fn wait<'a, T>(&self, g: MutexGuard<'a, T>) -> MutexGuard<'a, T>
Blocks the current task until this condition variable receives a notification.
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