Guava EventBus dispatching

后端 未结 4 630
礼貌的吻别
礼貌的吻别 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:19

    EventBus generally operates on the principle that the code posting an event to the bus shouldn't care about what the subscribers do with the events or when, other than that the order the events were posted in is respected (in the case of a synchronous event bus anyway).

    If you want specific methods to be called at specific times in the course of your method and you want to be sure those methods complete before your method continues (as you seem to in your example), why not call those methods directly? When you use an event bus, you're explicitly separating your code from what exactly happens in response to a given event. This is desirable in many cases and is the main reason EventBus exists, but it doesn't seem to be quite what you want here.

提交回复
热议问题