use crate::model::crdt::crdt::CrdtDeltaBox;
#[derive(Debug, Clone)]
pub struct DeltaBoxNotifier {
tx: tokio::sync::broadcast::Sender<CrdtDeltaBox>,
}
impl DeltaBoxNotifier {
pub(crate) fn new() -> Self {
let (tx, _) = tokio::sync::broadcast::channel(16);
Self { tx }
}
pub(crate) fn notify(&self, delta_box: CrdtDeltaBox) {
match self.tx.send(delta_box) {
Ok(_) => (),
Err(e) => {
tracing::error!("send update notifier event failed: {}", e);
}
}
}
pub fn listen(&self) -> tokio::sync::broadcast::Receiver<CrdtDeltaBox> {
self.tx.subscribe()
}
}