Guava EventBus dispatching

后端 未结 4 637
礼貌的吻别
礼貌的吻别 2021-02-07 16:35

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:17

    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
    

提交回复
热议问题