Guava EventBus dispatching

后端 未结 4 1248
轻奢々
轻奢々 2021-02-07 16:30

I\'m using Guava\'s EventBus to kick off some processing and report results. Here\'s a very simple compilable example:

import com.google.common.eventbus.EventBu         


        
4条回答
  •  太阳男子
    2021-02-07 17:28

    I know this question is 4 years old, but I just ran into the same problem today. There is a simple (and counter-intuitive) change to get the behavior you want. Per https://stackoverflow.com/a/53136251/1296767, you can use an AsyncEventBus with a DirectExecutor:

    public static EventBus bus = new AsyncEventBus(MoreExecutors.newDirectExecutorService());
    

    Running your test code with the above change, the results are exactly what you want:

    Got processing request - starting processing
    Processing has started
    Generating results
    got results
    Generating more results
    got results
    Processing has completed
    

提交回复
热议问题