use tokio::sync::watch::{channel, error::RecvError, Receiver, Sender};
#[derive(Clone, Default)]
pub struct BlockTx(Sender<()>);
#[derive(Clone)]
pub struct BlockRx(Receiver<()>);
impl BlockTx {
pub fn new() -> Self {
let (block_tx, _block_rx) = channel(());
Self(block_tx)
}
pub fn notify(&self) {
let _ = self.0.send(());
}
pub fn new_listener(&self) -> BlockRx {
BlockRx(self.0.subscribe())
}
pub fn receiver_count(&self) -> usize {
self.0.receiver_count()
}
}
impl BlockRx {
pub async fn changed(&mut self) -> Result<(), RecvError> {
self.0.changed().await
}
}