use crate::common::StaticTypeMap;
use tokio::sync::broadcast::Sender;
mod subscription;
#[cfg(test)]
mod test;
pub use subscription::*;
static CHANNELS: StaticTypeMap = StaticTypeMap::new();
pub trait Broadcast: Sized + 'static {
const BUFFER_SIZE: usize;
const DEBUG_NAME: &'static str;
type Payload: Clone + Send;
}
pub async fn notify<B: Broadcast>(payload: B::Payload) {
let id = id!(B);
let channels = CHANNELS.read().await;
let sender = match channels.get(&id) {
Some(sender) => sender,
None => return,
};
let sender: &Sender<_> = unsafe { sender.get_ref() };
let _ = sender.send(payload);
}