Trait reth_rpc_eth_api::helpers::blocking_task::SpawnBlocking
source · 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§
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 tracing_task_guard(&self) -> &BlockingTaskGuard
fn tracing_task_guard(&self) -> &BlockingTaskGuard
Returns handle to semaphore for pool of CPU heavy blocking tasks.
Provided Methods§
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
.
sourcefn spawn_blocking_io<F, R>(
&self,
f: F,
) -> impl Future<Output = Result<R, Self::Error>> + Send
fn spawn_blocking_io<F, R>( &self, f: F, ) -> impl Future<Output = Result<R, Self::Error>> + 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, Self::Error>> + Send
fn spawn_tracing<F, R>( &self, f: F, ) -> impl Future<Output = Result<R, Self::Error>> + 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/.