2

I am using greenroot eventbus to pass event payloads between the 2 components of my application in an async manner using the @Subscribe annotation to subscribe to events. The issue is if multiple instances of the class having @Subscribe annotation are registered with the event bus, All of them receive the same event payload and the computation is done multiple times.(As many instances i have created.)

Is there a way for the event bus to provide the event payload to only a single instance of my class i.e

If my subscribe method looks like:

public class A {

 A() {
   eventBus.register(this);
 }

 @Subscribe
public void consumeEvent(String s) {
   // do something
}

}

If i create 5 instances of class A, and pass 5 strings to the eventbus, all of the subscribed instances should get 1 instance each.

Is there a way i can avoid this redundant computation because of multiple objects?.

user2565192
  • 694
  • 1
  • 8
  • 19

0 Answers0