#[cfg(feature = "ws-server")]
pub use inner::WsBroadcastSink;
#[cfg(feature = "ws-server")]
mod inner {
use crate::{ProofEvent, ProofEventSink};
#[derive(Clone)]
pub struct WsBroadcastSink {
tx: tokio::sync::broadcast::Sender<String>,
}
impl WsBroadcastSink {
pub fn new(capacity: usize) -> Self {
let (tx, _) = tokio::sync::broadcast::channel(capacity);
Self { tx }
}
pub fn subscribe(&self) -> tokio::sync::broadcast::Receiver<String> {
self.tx.subscribe()
}
}
impl ProofEventSink for WsBroadcastSink {
#[inline]
fn emit(&self, event: ProofEvent) {
if let Ok(json) = serde_json::to_string(&event) {
let _ = self.tx.send(json);
}
}
fn flush(&self) {}
}
}