pubsub icon indicating copy to clipboard operation
pubsub copied to clipboard

Unsubscribing annotated classes

Open cardosso opened this issue 9 years ago • 0 comments

If I have a class annotated as a subscriber such as:

public class SampleSub { @Subscribe(topics = Topics.TEST_TOPIC) void consumeEvent(Event<String> data) { //do something } }

It doesn't seem to be possible to ever unsubscribe it from the dispatcher. This is because looking at the SubscriptionManager code what gets subscribed in this case is the SampleSub class, but I cannot do something like: dispatcher.unsubscribe(this); //this being the SampleSub class instance

Because the unsubscribe method is expecting a Subscriber<E> so code won't even compile, also cannot do: dispatcher.unsubscribe(this::consumeEvent);

This will compile, but the instance will never be removed from SubscriptionManager because this test will always fail: if (subscription.getSubscriber().equals(subscriber)) {

As it will be comparing a method reference with a class instance.

So it doesn't seem to be able to ever unregister annotated classes from the EventBus which basically renders this function useless unless you want to subscribe to some event during the whole lifecycle of your app.

Could this be fixed or should I move away from annotated subscribers?

cardosso avatar Aug 09 '16 05:08 cardosso