1use aios_spec::{IngestedRawEvent, IntentBatch};
10use tokio::sync::mpsc;
11
12pub struct ActionBus {
18 raw_events_rx: mpsc::Receiver<IngestedRawEvent>,
19 raw_events_tx: mpsc::Sender<IngestedRawEvent>,
20 intent_rx: mpsc::Receiver<IntentBatch>,
21 intent_tx: mpsc::Sender<IntentBatch>,
22}
23
24impl ActionBus {
25 pub fn new(capacity: usize) -> Self {
26 let (raw_events_tx, raw_events_rx) = mpsc::channel(capacity);
27 let (intent_tx, intent_rx) = mpsc::channel(capacity);
28 Self {
29 raw_events_rx,
30 raw_events_tx,
31 intent_rx,
32 intent_tx,
33 }
34 }
35
36 pub fn raw_sender(&self) -> mpsc::Sender<IngestedRawEvent> {
38 self.raw_events_tx.clone()
39 }
40
41 pub fn intent_sender(&self) -> mpsc::Sender<IntentBatch> {
43 self.intent_tx.clone()
44 }
45
46 pub async fn recv_raw(&mut self) -> Option<IngestedRawEvent> {
48 self.raw_events_rx.recv().await
49 }
50
51 pub async fn recv_intent(&mut self) -> Option<IntentBatch> {
53 self.intent_rx.recv().await
54 }
55}
56
57impl Default for ActionBus {
58 fn default() -> Self {
59 Self::new(1024)
60 }
61}