pub trait SpawnBlocking: Clone + Send + Sync + 'static {
    // Required method
    fn io_task_spawner(&self) -> impl TaskSpawner;

    // Provided method
    fn spawn_blocking_io<F, R>(
        &self,
        f: F
    ) -> impl Future<Output = Result<R, ErrorObjectOwned>> + Send
       where F: FnOnce(Self) -> Result<R, ErrorObjectOwned> + Send + 'static,
             R: Send + 'static { ... }
}
Expand description

Executes code on a blocking thread.

Required Methods§

source

fn io_task_spawner(&self) -> impl TaskSpawner

Returns a handle for spawning IO heavy blocking tasks.

Runtime access in default trait method implementations.

Provided Methods§

source

fn spawn_blocking_io<F, R>( &self, f: F ) -> impl Future<Output = Result<R, ErrorObjectOwned>> + Send
where F: FnOnce(Self) -> Result<R, ErrorObjectOwned> + Send + 'static, R: Send + 'static,

Executes the future on a new blocking task.

Note: This is expected for futures that are dominated by blocking IO operations, for tracing or CPU bound operations in general use spawn_tracing.

Object Safety§

This trait is not object safe.

Implementors§