pub trait SpawnBlocking:
    EthApiTypes
    + Clone
    + Send
    + Sync
    + 'static {
    // Required methods
    fn io_task_spawner(&self) -> impl TaskSpawner;
    fn tracing_task_pool(&self) -> &BlockingTaskPool;
    fn tracing_task_guard(&self) -> &BlockingTaskGuard;

    // Provided methods
    fn acquire_owned(
        &self,
    ) -> impl Future<Output = Result<OwnedSemaphorePermit, AcquireError>> + Send { ... }
    fn acquire_many_owned(
        &self,
        n: u32,
    ) -> impl Future<Output = Result<OwnedSemaphorePermit, AcquireError>> + Send { ... }
    fn spawn_blocking_io<F, R>(
        &self,
        f: F,
    ) -> impl Future<Output = Result<R, Self::Error>> + Send
       where F: FnOnce(Self) -> Result<R, Self::Error> + Send + 'static,
             R: Send + 'static { ... }
    fn spawn_tracing<F, R>(
        &self,
        f: F,
    ) -> impl Future<Output = Result<R, Self::Error>> + Send
       where F: FnOnce(Self) -> Result<R, Self::Error> + 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.

source

fn tracing_task_pool(&self) -> &BlockingTaskPool

Returns a handle for spawning CPU heavy blocking tasks.

Thread pool access in default trait method implementations.

source

fn tracing_task_guard(&self) -> &BlockingTaskGuard

Returns handle to semaphore for pool of CPU heavy blocking tasks.

Provided Methods§

source

fn acquire_owned( &self, ) -> impl Future<Output = Result<OwnedSemaphorePermit, AcquireError>> + Send

source

fn acquire_many_owned( &self, n: u32, ) -> impl Future<Output = Result<OwnedSemaphorePermit, AcquireError>> + Send

source

fn spawn_blocking_io<F, R>( &self, f: F, ) -> impl Future<Output = Result<R, Self::Error>> + Send
where F: FnOnce(Self) -> Result<R, Self::Error> + 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.

source

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

Executes a blocking task on the tracing pool.

Note: This is expected for futures that are predominantly CPU bound, as it uses rayon under the hood, for blocking IO futures use spawn_blocking. See https://ryhl.io/blog/async-what-is-blocking/.

Object Safety§

This trait is not object safe.

Implementors§