Trait reth::rpc::api::servers::eth::helpers::blocking_task::SpawnBlocking

source ·
pub trait SpawnBlocking: Clone + Send + Sync + 'static {
    // Required methods
    fn io_task_spawner(&self) -> impl TaskSpawner;
    fn tracing_task_pool(&self) -> &BlockingTaskPool;
    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;

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

Provided Methods§

source

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

source§

impl<Provider, Pool, Network, EvmConfig> SpawnBlocking for EthApi<Provider, Pool, Network, EvmConfig>
where EthApi<Provider, Pool, Network, EvmConfig>: Clone + Send + Sync + 'static,