mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: add spawn helpers (#7396)
This commit is contained in:
@ -166,6 +166,8 @@ where
|
||||
///
|
||||
/// This accepts a closure that creates a new future using a clone of this type and spawns the
|
||||
/// future onto a new task that is allowed to block.
|
||||
///
|
||||
/// Note: This is expected for futures that are dominated by blocking IO operations.
|
||||
pub(crate) async fn on_blocking_task<C, F, R>(&self, c: C) -> EthResult<R>
|
||||
where
|
||||
C: FnOnce(Self) -> F,
|
||||
|
||||
@ -47,6 +47,7 @@ use revm::{
|
||||
},
|
||||
Inspector,
|
||||
};
|
||||
use std::future::Future;
|
||||
|
||||
#[cfg(feature = "optimism")]
|
||||
use crate::eth::api::optimism::OptimismTxMeta;
|
||||
@ -88,6 +89,24 @@ pub trait EthTransactions: Send + Sync {
|
||||
/// Returns default gas limit to use for `eth_call` and tracing RPC methods.
|
||||
fn call_gas_limit(&self) -> u64;
|
||||
|
||||
/// 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 [Self::spawn_blocking].
|
||||
async fn spawn_blocking_future<F, R>(&self, c: F) -> EthResult<R>
|
||||
where
|
||||
F: Future<Output = EthResult<R>> + Send + 'static,
|
||||
R: Send + 'static;
|
||||
|
||||
/// Executes a blocking on the tracing pol.
|
||||
///
|
||||
/// Note: This is expected for futures that are predominantly CPU bound, for blocking IO futures
|
||||
/// use [Self::spawn_blocking_future].
|
||||
async fn spawn_blocking<F, R>(&self, c: F) -> EthResult<R>
|
||||
where
|
||||
F: FnOnce() -> EthResult<R> + Send + 'static,
|
||||
R: Send + 'static;
|
||||
|
||||
/// Returns the state at the given [BlockId]
|
||||
fn state_at(&self, at: BlockId) -> EthResult<StateProviderBox>;
|
||||
|
||||
@ -464,6 +483,22 @@ where
|
||||
self.inner.gas_cap
|
||||
}
|
||||
|
||||
async fn spawn_blocking_future<F, R>(&self, c: F) -> EthResult<R>
|
||||
where
|
||||
F: Future<Output = EthResult<R>> + Send + 'static,
|
||||
R: Send + 'static,
|
||||
{
|
||||
self.on_blocking_task(|_| c).await
|
||||
}
|
||||
|
||||
async fn spawn_blocking<F, R>(&self, c: F) -> EthResult<R>
|
||||
where
|
||||
F: FnOnce() -> EthResult<R> + Send + 'static,
|
||||
R: Send + 'static,
|
||||
{
|
||||
self.spawn_tracing_task_with(move |_| c()).await
|
||||
}
|
||||
|
||||
fn state_at(&self, at: BlockId) -> EthResult<StateProviderBox> {
|
||||
self.state_at_block_id(at)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user