use super::context;
use crate::{tokio, Runner as _};
use criterion::async_executor::AsyncExecutor;
use futures::Future;
#[derive(Clone)]
pub struct Runner {
cfg: tokio::Config,
}
impl Runner {
pub const fn new(cfg: tokio::Config) -> Self {
Self { cfg }
}
}
impl Default for Runner {
fn default() -> Self {
Self::new(tokio::Config::default())
}
}
impl AsyncExecutor for &Runner {
fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
let runner = tokio::Runner::new(self.cfg.clone());
let result = runner.start(|ctx| {
context::set(ctx);
future
});
context::clear();
result
}
}