(&self, def: &BusEventDef, properties: serde_json::Value)
| 45 | } |
| 46 | |
| 47 | pub async fn publish(&self, def: &BusEventDef, properties: serde_json::Value) { |
| 48 | tracing::info!(event_type = def.event_type, "publishing event"); |
| 49 | |
| 50 | let event = BusEvent { |
| 51 | event_type: def.event_type.to_string(), |
| 52 | properties: properties.clone(), |
| 53 | }; |
| 54 | |
| 55 | let _ = self.tx.send(event.clone()); |
| 56 | |
| 57 | let subscribers = self.subscribers.read().await; |
| 58 | if let Some(subs) = subscribers.get(def.event_type) { |
| 59 | for sub in subs { |
| 60 | (sub.callback)(def.event_type, properties.clone()); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | let wildcard = self.wildcard_subscribers.read().await; |
| 65 | for sub in wildcard.iter() { |
| 66 | (sub.callback)(def.event_type, properties.clone()); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | pub async fn subscribe<F>(&self, def: &BusEventDef, callback: F) -> u64 |
| 71 | where |
no test coverage detected