Skip to main content

crows_wasm/executors/
mod.rs

1mod constant_arrival_rate;
2use constant_arrival_rate::ConstantArrivalRateExecutor;
3use crows_shared::Config;
4use crate::Runtime;
5
6pub trait Executor {
7    #[allow(async_fn_in_trait)]
8    async fn prepare(&mut self) -> anyhow::Result<()>;
9    #[allow(async_fn_in_trait)]
10    async fn run(&mut self) -> anyhow::Result<()>;
11}
12
13pub enum Executors {
14    ConstantArrivalRateExecutor(ConstantArrivalRateExecutor),
15}
16
17impl Executors {
18    pub async fn create_executor(config: Config, runtime: Runtime) -> Self {
19        match config {
20            Config::ConstantArrivalRate(config) => {
21                Executors::ConstantArrivalRateExecutor(ConstantArrivalRateExecutor {
22                    config,
23                    runtime,
24                })
25            }
26        }
27    }
28
29    pub async fn run(&mut self) {
30        match self {
31            Executors::ConstantArrivalRateExecutor(ref mut executor) => {
32                executor.run().await.unwrap()
33            }
34        }
35    }
36
37    pub async fn prepare(&mut self) {
38        match self {
39            Executors::ConstantArrivalRateExecutor(ref mut executor) => {
40                executor.prepare().await.unwrap()
41            }
42        }
43    }
44}