Skip to main content

bpm_engine_runtime/
engine.rs

1use super::handler::{EngineContext, EventHandler};
2use super::pump::EventPump;
3use bpm_engine_core::EngineEvent;
4use bpm_engine_storage::TokenStore;
5use std::sync::Arc;
6
7pub struct Engine<S> {
8    store: Arc<S>,
9}
10
11impl<S> Engine<S>
12where
13    S: TokenStore + Send + Sync + 'static,
14{
15    pub fn new(store: Arc<S>) -> Self {
16        Self { store }
17    }
18
19    pub async fn tick(&self) -> anyhow::Result<()> {
20        // 1. claim tokens
21        // 2. execute
22        // 3. persist
23        let _ = &self.store;
24        Ok(())
25    }
26}
27
28/// BpmEngine aggregates handlers and runs event pump (design: overview ยง3).
29pub struct BpmEngine {
30    pub handlers: Vec<Box<dyn EventHandler>>,
31}
32
33impl BpmEngine {
34    pub fn new(handlers: Vec<Box<dyn EventHandler>>) -> Self {
35        BpmEngine { handlers }
36    }
37
38    /// Run event pump with initial event (async; uses storage via ctx).
39    pub async fn run_async(&self, initial: EngineEvent, ctx: &mut EngineContext) {
40        EventPump::run_async(&self.handlers, initial, ctx).await;
41    }
42}