coven_foundation/blocking.rs
1//! Bounded-stack execution for CPU work reached through nested async protocol verification.
2
3#[derive(Debug, thiserror::Error)]
4pub enum BlockingTaskError {
5 #[error("blocking task failed: {0}")]
6 Join(#[from] tokio::task::JoinError),
7}
8
9pub async fn run<T>(work: impl FnOnce() -> T + Send + 'static) -> Result<T, BlockingTaskError>
10where
11 T: Send + 'static,
12{
13 tokio::task::spawn_blocking(work)
14 .await
15 .map_err(BlockingTaskError::Join)
16}