aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Events
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-10-13 17:19:13 -0500
committerJP Dillingham <jp@dillingham.me>2024-10-13 17:19:13 -0500
commita2e2df33837a9439c46311bbc5e96d4d4990a25f (patch)
treefabb8c404cbfc0423bfd46469acb21fba7618648 /src/slskd/Events
parentc22ca22d299c0c8ad202c852c95f12fcff609249 (diff)
downloadslskd-a2e2df33837a9439c46311bbc5e96d4d4990a25f.tar.gz
add special case for subscribers to Event
Diffstat (limited to 'src/slskd/Events')
-rw-r--r--src/slskd/Events/EventBus.cs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/slskd/Events/EventBus.cs b/src/slskd/Events/EventBus.cs
index e5552d2d..46e55565 100644
--- a/src/slskd/Events/EventBus.cs
+++ b/src/slskd/Events/EventBus.cs
@@ -78,7 +78,7 @@ public class EventBus
// save the event to the database before broadcasting to consumers
Events.Add(EventRecord.From<T>(data));
- // broadcast the event in a fire-and-forget fashion
+ // broadcast the event to granular subscribers in a fire-and-forget fashion
// we don't need to wait for anything, just need to kick off the tasks
// if something throws it will be logged and the consumer can figure it out
if (Subscriptions.TryGetValue(typeof(T), out var subscribers))
@@ -94,6 +94,17 @@ public class EventBus
{
Log.Debug("No subscribers for {Type}", typeof(T));
}
+
+ // broadcast the event to catch-all subscribers of type Event; listening for all types
+ if (Subscriptions.TryGetValue(typeof(Event), out subscribers))
+ {
+ Log.Debug("{Count} catch-all subscriber(s) for {Type}: {Names}", subscribers.Count, typeof(Event), string.Join(", ", subscribers.Keys));
+
+ // we don't care about any of these tasks; contractually we are only obligated to invoke them
+ _ = Task.WhenAll(subscribers.Select(subscriber =>
+ Task.Run(() => (subscriber.Value as Func<Event, Task>)(data))
+ .ContinueWith(task => Log.Error(task.Exception, "Catch-All Subscriber {Name} for {Type} encountered an error: {Message}", subscriber.Key, typeof(Event), task.Exception.Message))));
+ }
}
/// <summary>