pub(crate) async fn join_logged(handle: tokio::task::JoinHandle<()>, what: &str) {
if let Err(e) = handle.await
&& !e.is_cancelled()
{
tracing::warn!(error = %e, task = what, "sibling relay task panicked");
}
}
pub(crate) struct AbortOnDrop(Option<tokio::task::JoinHandle<()>>);
impl AbortOnDrop {
pub(crate) fn take(mut self) -> tokio::task::JoinHandle<()> {
self.0.take().expect("AbortOnDrop::take called once")
}
}
impl Drop for AbortOnDrop {
fn drop(&mut self) {
if let Some(handle) = &self.0 {
handle.abort();
}
}
}
pub(crate) fn spawn_guarded<F>(fut: F) -> AbortOnDrop
where
F: std::future::Future<Output = ()> + Send + 'static,
{
AbortOnDrop(Some(tokio::spawn(fut)))
}