signer-daemon 0.3.2

Signer daemon package.
Documentation
/**
 * 成功应用至数据库的 DeltaBox 会通过 DeltaBoxNotifier 进行广播
 * 这允许状态驱动的客户端通过监听 DeltaBoxNotifier 按需更新页面内容
 */
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()
    }
}