From 21c7e4d050961bca34ff758965ffd4e27c183f47 Mon Sep 17 00:00:00 2001 From: "Adam R. Grey" Date: Fri, 3 Sep 2021 04:45:47 -0400 Subject: [PATCH] redundant unsubscribing should be fine --- franz/Telefranz.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/franz/Telefranz.cs b/franz/Telefranz.cs index e79fcfd..c4a6ee7 100644 --- a/franz/Telefranz.cs +++ b/franz/Telefranz.cs @@ -138,14 +138,22 @@ namespace franz _TelefranzConsumers.wrappings[theAction] = wrapped; topicSubscribers[topic]++; } - public void removeHandler(Action theAction) where T : silver_messages.message + public bool removeHandler(Action theAction) where T : silver_messages.message { topicConsumers[typeof(T).ToString()].MessageReceived -= _TelefranzConsumers.wrappings[theAction]; - _TelefranzConsumers.wrappings.Remove(theAction); - topicSubscribers[typeof(T).ToString()]--; - if (topicSubscribers[typeof(T).ToString()] == 0) + if (_TelefranzConsumers.wrappings.ContainsKey(theAction)) { - topicConsumers[typeof(T).ToString()].StopConsume(); + _TelefranzConsumers.wrappings.Remove(theAction); + topicSubscribers[typeof(T).ToString()]--; + if (topicSubscribers[typeof(T).ToString()] == 0) + { + topicConsumers[typeof(T).ToString()].StopConsume(); + } + return true; + } + else + { + return false; } }