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§
Sourcefn io_task_spawner(&self) -> impl TaskSpawner
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§
Sourcefn spawn_blocking_io<F, R>(
&self,
f: F,
) -> impl Future<Output = Result<R, ErrorObjectOwned>> + Send
fn spawn_blocking_io<F, R>( &self, f: F, ) -> impl Future<Output = Result<R, ErrorObjectOwned>> + Send
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.