use crate::cmap::PoolGeneration;
#[derive(Clone, Debug)]
struct PoolStatus {
generation: PoolGeneration,
}
pub(super) fn channel(init: PoolGeneration) -> (PoolGenerationPublisher, PoolGenerationSubscriber) {
let (sender, receiver) = tokio::sync::watch::channel(PoolStatus { generation: init });
(
PoolGenerationPublisher { sender },
PoolGenerationSubscriber { receiver },
)
}
#[derive(Debug)]
pub(super) struct PoolGenerationPublisher {
sender: tokio::sync::watch::Sender<PoolStatus>,
}
impl PoolGenerationPublisher {
pub(super) fn publish(&self, new_generation: PoolGeneration) {
let new_status = PoolStatus {
generation: new_generation,
};
let _: std::result::Result<_, _> = self.sender.send(new_status);
}
}
#[derive(Clone, Debug)]
pub(crate) struct PoolGenerationSubscriber {
receiver: tokio::sync::watch::Receiver<PoolStatus>,
}
impl PoolGenerationSubscriber {
pub(crate) fn generation(&self) -> PoolGeneration {
self.receiver.borrow().generation.clone()
}
}