reactive_graph_reactive_service_api/
event_channels.rs1use std::ops::Deref;
2
3use crossbeam::channel::Receiver;
4use crossbeam::channel::Sender;
5use dashmap::DashMap;
6use serde_json::Value;
7
8pub struct EventChannels(DashMap<u128, (Sender<Value>, Receiver<Value>)>);
9
10impl EventChannels {
11 pub fn new() -> Self {
12 Self(DashMap::new())
13 }
14
15 pub fn sender(&self, handle_id: &u128) -> Option<Sender<Value>> {
16 self.0.get(handle_id).map(|channel| channel.0.clone())
17 }
18
19 pub fn receiver(&self, handle_id: &u128) -> Option<Receiver<Value>> {
20 self.0.get(handle_id).map(|channel| channel.1.clone())
21 }
22}
23
24impl Deref for EventChannels {
25 type Target = DashMap<u128, (Sender<Value>, Receiver<Value>)>;
26
27 fn deref(&self) -> &Self::Target {
28 &self.0
29 }
30}
31
32impl Default for EventChannels {
33 fn default() -> Self {
34 Self::new()
35 }
36}