use std::future::Future;
use async_scoped::TokioScope;
use tokio::task::JoinError;
pub async fn await_blocking<F: FnOnce() -> T + Send, T: Send + 'static>(
f: F,
) -> Result<T, JoinError> {
unsafe { TokioScope::scope_and_collect(|scope| scope.spawn_blocking(f)) }.await.1.pop().unwrap()
}
pub async fn await_scoped_vec<F: Future<Output = T> + Send, T: Send + 'static>(
f: impl IntoIterator<Item = F>,
) -> Result<Vec<T>, JoinError> {
unsafe {
TokioScope::scope_and_collect(|scope| {
f.into_iter().map(|f| scope.spawn(f)).collect::<Vec<_>>()
})
}
.await
.1
.into_iter()
.collect::<Result<Vec<_>, _>>()
}