dead code

This commit is contained in:
psykose 2024-11-18 22:58:44 +01:00
parent b036fb877a
commit 6f925f9922
Signed by: psykose
SSH key fingerprint: SHA256:pRMVjV3kRB6zl+wNx+sV8KoMnPqQAW6v8dNCxsCGZv8

View file

@ -1,34 +0,0 @@
// nice wrapper to have a Default impl for a (Sender, InactiveReceiver) pair
use async_broadcast::{broadcast, InactiveReceiver, Receiver, Sender, TrySendError};
pub struct Broadcast<const N: usize, T> {
pub sender: Sender<T>,
inactive_receiver: InactiveReceiver<T>,
}
impl<const N: usize, T> Default for Broadcast<N, T> {
fn default() -> Self {
let (sender, receiver) = broadcast(N);
Self {
sender,
inactive_receiver: receiver.deactivate(),
}
}
}
impl<const N: usize, T> Broadcast<N, T> where T: Clone {
pub fn receiver(&self) -> Receiver<T> {
self.inactive_receiver.activate_cloned()
}
// like sender.try_broadcast, but ignores if there aren't any active listeners
pub fn try_broadcast(&self, msg: T) -> Result<(), TrySendError<T>> {
match self.sender.try_broadcast(msg) {
Err(TrySendError::Inactive(_)) => Ok(()), // ignore
Err(err) => Err(err),
Ok(Some(_)) => unreachable!("we do not enable overflow mode"),
Ok(None) => Ok(()),
}
}
}