use std::sync::OnceLock; use tokio::sync::watch; static CHANGES: OnceLock> = OnceLock::new(); fn sender() -> &'static watch::Sender { CHANGES.get_or_init(|| watch::channel(0).0) } pub fn subscribe() -> watch::Receiver { sender().subscribe() } pub fn bump() { crate::live::next_live_seq(); sender().send_modify(|generation| *generation = generation.wrapping_add(1)); crate::live::admin().bump(&crate::live::Topic::AdminHealth); } #[cfg(test)] mod tests { use std::time::Duration; use super::*; #[tokio::test] async fn a_bump_wakes_a_subscriber_that_was_subscribed_before_it() { let mut rx = subscribe(); bump(); tokio::time::timeout(Duration::from_secs(1), rx.changed()) .await .expect("woken in time") .expect("the signal is open"); } }