pub(crate) fn shutdown_token() -> (ShutdownToken, ShutdownListener) {
let (tx, rx) = tokio::sync::watch::channel(());
(ShutdownToken { _inner: tx }, ShutdownListener { inner: rx })
}
pub(crate) struct ShutdownToken {
_inner: tokio::sync::watch::Sender<()>,
}
#[derive(Clone)]
pub(crate) struct ShutdownListener {
inner: tokio::sync::watch::Receiver<()>,
}
impl ShutdownListener {
pub(crate) async fn listen(&mut self) {
loop {
match self.inner.changed().await {
Ok(()) => {}
Err(_) => return,
}
}
}
}