reth::rpc::api::servers::eth::helpers

Trait SpawnBlocking

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§

fn io_task_spawner(&self) -> impl TaskSpawner

Returns a handle for spawning IO heavy blocking tasks.

Runtime access in default trait method implementations.

fn tracing_task_pool(&self) -> &BlockingTaskPool

Returns a handle for spawning CPU heavy blocking tasks.

Thread pool access in default trait method implementations.

fn tracing_task_guard(&self) -> &BlockingTaskGuard

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

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,

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.

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

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§

Source§

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