Skip to main content

spawn_blocking

Function spawn_blocking 

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

Spawns a blocking operation and returns a Future that yields until completion.

This function runs the provided closure on the runtime blocking pool when a current Cx is available, and falls back to a dedicated thread when no runtime context is set.

§Type Bounds

  • F: FnOnce() -> T + Send + 'static - The closure must be sendable to another thread
  • T: Send + 'static - The return value must be sendable back

§Cancel Safety

If this future is dropped before completion, the blocking operation continues to run but its result is discarded.

§Panics

If the blocking operation panics, the panic is captured and re-raised when the future is awaited.