Ver Fonte

system/subscriber: add notify_with_exclude function to Subscriber

ghassmo há 4 anos atrás
pai
commit
789bbf93c6
1 ficheiros alterados com 18 adições e 0 exclusões
  1. 18 0
      src/system/subscriber.rs

+ 18 - 0
src/system/subscriber.rs

@@ -16,6 +16,10 @@ pub struct Subscription<T> {
 }
 
 impl<T: Clone> Subscription<T> {
+    pub fn get_id(&self) -> SubscriptionId {
+        self.id
+    }
+
     pub async fn receive(&self) -> T {
         let message_result = self.recv_queue.recv().await;
 
@@ -81,4 +85,18 @@ impl<T: Clone> Subscriber<T> {
             }
         }
     }
+
+    pub async fn notify_with_exclude(&self, message_result: T, exclude_list: &[SubscriptionId]) {
+        for (id, sub) in (*self.subs.lock().await).iter() {
+            if exclude_list.contains(id) {
+                continue
+            }
+            match sub.send(message_result.clone()).await {
+                Ok(()) => {}
+                Err(err) => {
+                    panic!("Error returned sending message in notify_with_exclude() call! {}", err);
+                }
+            }
+        }
+    }
 }