Fix core unsubscribe by subject #1363
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1232
Context
The dispatcher api allows subscribe
subscribe("foo");, in which case it will use the message handler provided when the dispatcher was created.subscribe("foo", nonDefaultHandler);.Problem
If you
unsubscribe("foo"), the dispatcher currently only unsubscribes the subscription with the default handler, meaning if you had subscribed with a non default handler, that subscriptions did not get unsubscribed. (That was the behavior reported in #1232)Desired Behavior
The dispatcher should unsubscribe for all handlers, default or otherwise, for a subject.
Considerations
You can only have one subscription for a subject with the default handler (otherwise you just get multiple copies of the same message to that handler) but you can have as many subscriptions for a subject if you provide a non default handler.
So if you do this:
you end up with 3 subscriptions.
Solution
Unsubscribe all subscriptions for the subject regardless of the handler.