doido_core/
notifications.rs1type Subscriber = Box<dyn Fn(&str, &str) + Send + Sync>;
7
8#[derive(Default)]
10pub struct Notifications {
11 subscribers: Vec<(String, Subscriber)>,
12}
13
14impl Notifications {
15 pub fn new() -> Self {
16 Self::default()
17 }
18
19 pub fn subscribe(
21 &mut self,
22 prefix: &str,
23 handler: impl Fn(&str, &str) + Send + Sync + 'static,
24 ) {
25 self.subscribers
26 .push((prefix.to_string(), Box::new(handler)));
27 }
28
29 pub fn instrument(&self, name: &str, payload: &str) {
31 for (prefix, handler) in &self.subscribers {
32 if name.starts_with(prefix.as_str()) {
33 handler(name, payload);
34 }
35 }
36 }
37}