use anyhow::anyhow;
use cid::Cid;
use fvm_shared::message::Message;
use lazy_static::lazy_static;
use super::{ApplyKind, ApplyRet, Executor};
lazy_static! {
static ref EXEC_POOL: yastl::Pool = yastl::Pool::with_config(
8,
yastl::ThreadConfig::new()
.prefix("fvm-executor")
.stack_size(64 << 20),
);
}
pub struct ThreadedExecutor<E>(pub E);
impl<E> Executor for ThreadedExecutor<E>
where
E: Executor + Send,
{
type Kernel = E::Kernel;
fn execute_message(
&mut self,
msg: Message,
apply_kind: ApplyKind,
raw_length: usize,
) -> anyhow::Result<ApplyRet> {
let mut ret = Err(anyhow!("failed to execute"));
EXEC_POOL.scoped(|scope| {
scope.execute(|| ret = self.0.execute_message(msg, apply_kind, raw_length));
});
ret
}
fn flush(&mut self) -> anyhow::Result<Cid> {
self.0.flush()
}
}