Skip to main content

spawn_blocking

Function spawn_blocking 

Source
pub fn spawn_blocking<F, R>(func: F) -> JoinHandle<R> ⓘ
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,
Available on crate feature tasks only.
Expand description

Spawns a blocking closure on the current tokio runtime, like [tokio::task::spawn_blocking].

The closure is boxed first, so tokio’s blocking task machinery is instantiated once per return type R instead of once per closure type.

§Panics

Panics if called outside of a tokio runtime context.