Trait SpawnBlocking

Source
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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§