Skip to main content

spawn_blocking

Function spawn_blocking 

Source
pub async fn spawn_blocking<T, F>(f: F) -> Result<T, SpawnBlockingError>
where T: Send + 'static, F: FnOnce() -> T + Send + 'static,
Expand description

Spawn a blocking task on the thread pool.

This function spawns the given closure on a blocking thread pool and returns a future that resolves to the result.

§Panics

Panics if called outside a runtime context.

§Examples

let result = vibeio::spawn_blocking(|| {
    // blocking work
    42
}).await?;