redundant unsubscribing should be fine

This commit is contained in:
Adam R. Grey 2021-09-03 04:45:47 -04:00
parent 5dde912564
commit 21c7e4d050

View File

@ -138,14 +138,22 @@ namespace franz
_TelefranzConsumers<T>.wrappings[theAction] = wrapped; _TelefranzConsumers<T>.wrappings[theAction] = wrapped;
topicSubscribers[topic]++; topicSubscribers[topic]++;
} }
public void removeHandler<T>(Action<T> theAction) where T : silver_messages.message public bool removeHandler<T>(Action<T> theAction) where T : silver_messages.message
{ {
topicConsumers[typeof(T).ToString()].MessageReceived -= _TelefranzConsumers<T>.wrappings[theAction]; topicConsumers[typeof(T).ToString()].MessageReceived -= _TelefranzConsumers<T>.wrappings[theAction];
_TelefranzConsumers<T>.wrappings.Remove(theAction); if (_TelefranzConsumers<T>.wrappings.ContainsKey(theAction))
topicSubscribers[typeof(T).ToString()]--;
if (topicSubscribers[typeof(T).ToString()] == 0)
{ {
topicConsumers[typeof(T).ToString()].StopConsume(); _TelefranzConsumers<T>.wrappings.Remove(theAction);
topicSubscribers[typeof(T).ToString()]--;
if (topicSubscribers[typeof(T).ToString()] == 0)
{
topicConsumers[typeof(T).ToString()].StopConsume();
}
return true;
}
else
{
return false;
} }
} }