forked from
microcosm.blue/microcosm-rs
Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
1use crate::error::DelayError;
2use crate::removable_delay_queue;
3use tokio::sync::broadcast;
4use tokio_util::sync::CancellationToken;
5
6pub async fn to_broadcast<T>(
7 source: removable_delay_queue::Output<(String, usize), T>,
8 dest: broadcast::Sender<T>,
9 shutdown: CancellationToken,
10) -> Result<(), DelayError> {
11 loop {
12 tokio::select! {
13 ev = source.next() => match ev {
14 Some(event) => {
15 let _ = dest.send(event); // only errors of there are no listeners, but that's normal
16 },
17 None => return Err(DelayError::DelayEnded),
18 },
19 _ = shutdown.cancelled() => return Ok(()),
20 }
21 }
22}