use async_std::channel::{Receiver, Sender};
#[derive(Clone)]
pub struct Notify(pub Option<Sender<()>>, pub Receiver<()>);
impl Notify {
pub fn new() -> Self {
let (send, recv) = async_std::channel::bounded(1);
Self(Some(send), recv)
}
pub async fn notify(&self) -> bool {
if let Some(sender) = &self.0 {
sender.close();
true
} else {
false
}
}
pub async fn wait(&self) -> bool {
if let Err(_) = self.1.recv().await {
false
} else {
true
}
}
}