use tracing::error; use std::future::Future; use tokio::sync::oneshot::channel; #[derive(Debug, thiserror::Error)] #[error("Task panicked")] pub(crate) struct Canceled; pub(crate) async fn spawn(f: F) -> Result where F: Future + 'static, T: 'static, { let (tx, rx) = channel(); actix_rt::spawn(async move { if let Err(_) = tx.send(f.await) { error!("rx dropped (this shouldn't happen)"); } }); rx.await.map_err(|_| Canceled) }