(&self, def: &BusEventDef, callback: F)
| 68 | } |
| 69 | |
| 70 | pub async fn subscribe<F>(&self, def: &BusEventDef, callback: F) -> u64 |
| 71 | where |
| 72 | F: Fn(&str, serde_json::Value) + Send + Sync + 'static, |
| 73 | { |
| 74 | let id = { |
| 75 | let mut next = self.next_id.write().await; |
| 76 | *next += 1; |
| 77 | *next |
| 78 | }; |
| 79 | |
| 80 | let mut subscribers = self.subscribers.write().await; |
| 81 | let subs = subscribers |
| 82 | .entry(def.event_type.to_string()) |
| 83 | .or_insert_with(Vec::new); |
| 84 | subs.push(Subscription { |
| 85 | id, |
| 86 | callback: Box::new(callback), |
| 87 | }); |
| 88 | |
| 89 | id |
| 90 | } |
| 91 | |
| 92 | pub async fn unsubscribe(&self, event_type: &str, id: u64) { |
| 93 | let mut subscribers = self.subscribers.write().await; |
no test coverage detected