tca/
event_sender_holder.rs1use std::sync::Arc;
2
3use crate::action_sender::ActionSender;
4use crate::store_event::StoreEvent;
5
6pub type EventSender<T> = tokio::sync::mpsc::UnboundedSender<T>;
7
8pub struct EventSenderHolder<Action>
9where
10 Action: Send + 'static,
11{
12 event_sender: EventSender<StoreEvent<Action>>,
13}
14
15impl<Action> EventSenderHolder<Action>
16where
17 Action: Send + 'static,
18{
19 pub fn new(event_sender: EventSender<StoreEvent<Action>>) -> Self {
20 Self { event_sender }
21 }
22
23 pub fn send_event(&self, evt: StoreEvent<Action>) {
24 self.event_sender.send(evt).unwrap();
25 }
26}
27
28impl<Action> ActionSender for Arc<EventSenderHolder<Action>>
29where
30 Action: Send,
31{
32 type SendableAction = Action;
33
34 fn send(&self, action: Action) {
35 self.send_event(StoreEvent::Action(action));
36 }
37}