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