This commit is contained in:
John Smith
2022-08-22 13:27:26 -04:00
parent 53ae04aff9
commit 997eca05b6
14 changed files with 920 additions and 154 deletions

View File

@@ -150,6 +150,23 @@ where
}
}
pub async fn blocking_wrapper<F, R>(blocking_task: F, err_result: R) -> R
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
// run blocking stuff in blocking thread
cfg_if! {
if #[cfg(feature="rt-async-std")] {
async_std::task::spawn_blocking(blocking_task).await
} else if #[cfg(feature="rt-tokio")] {
tokio::task::spawn_blocking(blocking_task).await.unwrap_or(err_result)
} else {
#[compile_error("must use an executor")]
}
}
}
pub fn get_concurrency() -> u32 {
std::thread::available_parallelism()
.map(|x| x.get())