| 49 | } |
| 50 | |
| 51 | pub fn subscribe(&mut self, topic: String) -> BrokerClient { |
| 52 | let (notify, _, subs) = self.subs.entry(topic.clone()).or_insert_with(|| { |
| 53 | let (s, r) = unbounded(); |
| 54 | (s, r, vec![]) |
| 55 | }); |
| 56 | let (s, r) = unbounded(); |
| 57 | subs.push(s.clone()); |
| 58 | self.count.fetch_add(1, Ordering::Relaxed); |
| 59 | BrokerClient { |
| 60 | id: subs.len() - 1, |
| 61 | notify: notify.clone(), |
| 62 | self_notify: s, |
| 63 | sub: r, |
| 64 | topic, |
| 65 | running: self.running.clone(), |
| 66 | count: self.count.clone(), |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | pub fn run(&mut self) -> JoinHandle<anyhow::Result<()>> { |
| 71 | self.running.store(true, Ordering::Relaxed); |