Trait reth::core::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§
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.
sourcefn tracing_task_pool(&self) -> &BlockingTaskPool
fn tracing_task_pool(&self) -> &BlockingTaskPool
Returns a handle for spawning CPU heavy blocking tasks.
Thread pool access in default trait method implementations.
sourcefn acquire_owned(
&self,
) -> impl Future<Output = Result<OwnedSemaphorePermit, AcquireError>> + Send
fn acquire_owned( &self, ) -> impl Future<Output = Result<OwnedSemaphorePermit, AcquireError>> + Send
See also Semaphore::acquire_owned
.
sourcefn acquire_many_owned(
&self,
n: u32,
) -> impl Future<Output = Result<OwnedSemaphorePermit, AcquireError>> + Send
fn acquire_many_owned( &self, n: u32, ) -> impl Future<Output = Result<OwnedSemaphorePermit, AcquireError>> + Send
See also Semaphore::acquire_many_owned
.
Provided Methods§
sourcefn spawn_blocking_io<F, R>(
&self,
f: F,
) -> impl Future<Output = Result<R, EthApiError>> + Send
fn spawn_blocking_io<F, R>( &self, f: F, ) -> impl Future<Output = Result<R, EthApiError>> + 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
.
sourcefn spawn_tracing<F, R>(
&self,
f: F,
) -> impl Future<Output = Result<R, EthApiError>> + Send
fn spawn_tracing<F, R>( &self, f: F, ) -> impl Future<Output = Result<R, EthApiError>> + Send
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/.