misc fixes for init

This commit is contained in:
Aiden McClelland
2021-09-07 00:27:33 -06:00
committed by Aiden McClelland
parent ccf505d0d3
commit 0886cd91a3
9 changed files with 167 additions and 105 deletions

View File

@@ -346,17 +346,16 @@ pub async fn daemon<F: FnMut() -> Fut, Fut: Future<Output = ()> + Send + 'static
cooldown: std::time::Duration,
mut shutdown: tokio::sync::broadcast::Receiver<Option<Shutdown>>,
) -> Result<(), anyhow::Error> {
while matches!(
shutdown.try_recv(),
Err(tokio::sync::broadcast::error::TryRecvError::Empty)
) {
loop {
match tokio::spawn(f()).await {
Err(e) if e.is_panic() => return Err(anyhow!("daemon panicked!")),
_ => (),
}
tokio::time::sleep(cooldown).await
tokio::select! {
_ = shutdown.recv() => return Ok(()),
_ = tokio::time::sleep(cooldown) => (),
}
}
Ok(())
}
pub trait SOption<T> {}