cyfs_util/util/
condvar_helper.rs1use std::sync::Arc;
2use async_std::sync::{Condvar, Mutex};
3
4pub struct AsyncCondvar {
5 mutex: Mutex<bool>,
6 condvar: Condvar,
7}
8pub type AsyncCondvarRef = Arc<AsyncCondvar>;
9
10impl AsyncCondvar {
11 pub fn new() -> AsyncCondvarRef {
12 AsyncCondvarRef::new(Self {
13 mutex: Mutex::new(false),
14 condvar: Condvar::new()
15 })
16 }
17
18 pub fn notify(&self) {
19 self.condvar.notify_one();
20 }
21
22 pub async fn wait(&self) {
23 let mutex = self.mutex.lock().await;
24 self.condvar.wait(mutex).await;
25 }
26}