From c818b42bb16bf8ade77b1ad20322cf4b30b43bc5 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 11 Aug 2024 17:13:55 -0500 Subject: hack shell service in --- src/slskd/Core/EventBus.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/EventBus.cs b/src/slskd/Core/EventBus.cs index 730fb848..9076f947 100644 --- a/src/slskd/Core/EventBus.cs +++ b/src/slskd/Core/EventBus.cs @@ -40,6 +40,11 @@ using Serilog; /// public class EventBus { + public EventBus() + { + Log.Debug("EventBus initialized"); + } + private ILogger Log { get; } = Serilog.Log.ForContext(); /// @@ -49,7 +54,7 @@ public class EventBus /// Note that the value is a dictionary to prevent multiple subscriptions from the same subscriber, and to /// support unsubscribing. /// - private ConcurrentDictionary>> Subscriptions { get; } = new(); + private ConcurrentDictionary>> Subscriptions { get; } = new(); /// /// Raises an event. @@ -64,6 +69,7 @@ public class EventBus if (!Subscriptions.TryGetValue(typeof(T), out var subscribers)) { Log.Debug("No subscribers for {Type}", typeof(T)); + return; } // we don't care about any of these tasks; contractually we are only obligated to invoke them @@ -94,13 +100,13 @@ public class EventBus Subscriptions.AddOrUpdate( key: typeof(T), - addValue: new ConcurrentDictionary>( - new Dictionary> { [subscriber] = (Func)callback }), + addValue: new ConcurrentDictionary>( + new Dictionary> { [subscriber] = (Func)callback }), updateValueFactory: (_, subscribers) => { subscribers.AddOrUpdate( key: subscriber, - addValue: (Func)callback, + addValue: (Func)callback, updateValueFactory: (_, existingSubscription) => { if (existingSubscription is not null) @@ -108,11 +114,13 @@ public class EventBus Log.Debug("Warning! {Type} subscriber {Name} attempted to create a redundant subscription. The existing subscription was overwritten.", typeof(T), subscriber); } - return (Func)callback; + return (Func)callback; }); return subscribers; }); + + Log.Debug("Subscribed {Name} to {Type}", subscriber, typeof(T)); } /// -- cgit v1.2.3