use tokio::task::JoinHandle;
use tokio_util::sync::CancellationToken;
pub(super) async fn supervise(
writer_handle: JoinHandle<&'static str>, reader_handle: JoinHandle<&'static str>,
worker_handles: Vec<JoinHandle<&'static str>>, cancel: CancellationToken,
) {
let mut tasks = tokio::task::JoinSet::new();
tasks.spawn(async move {
match writer_handle.await {
Ok(name) => name,
Err(e) => {
if e.is_panic() {
tracing::error!("SPDY writer panicked — session poisoned, no restart: {e}");
}
"writer"
}
}
});
tasks.spawn(async move {
match reader_handle.await {
Ok(name) => name,
Err(e) => {
if e.is_panic() {
tracing::error!("SPDY reader panicked — session poisoned, no restart: {e}");
}
"reader"
}
}
});
for (i, wh) in worker_handles.into_iter().enumerate() {
tasks.spawn(async move {
match wh.await {
Ok(name) => name,
Err(e) => {
if e.is_panic() {
tracing::error!(
worker_id = i,
"SPDY frame worker panicked — session poisoned, no restart: {e}"
);
}
"worker"
}
}
});
}
if let Some(result) = tasks.join_next().await {
match result {
Ok(name) => tracing::debug!("SPDY supervisor: {name} exited first"),
Err(e) => tracing::debug!("SPDY supervisor: task join error: {e}"),
}
}
cancel.cancel();
}