Please help me to figure out if the following scenarios are valid if I'm going to use Otto Bus lib.
According to the Otto documentation
Posting to the bus is a synchronous action so when program execution continues it is guaranteed that all subscribers have been called.
Does it mean that any of event subscribers are not executed in parallel?
Thanks
When posting an event, Otto iterates through a Set
of handlers to dispatch the event to them.
Since Set
is an unordered collection, it is not guaranteed that this will happen in the order you've registered them (or any particular order).
The relevant part from the source code:
Set<Class<?>> dispatchTypes = flattenHierarchy(event.getClass());
boolean dispatched = false;
for (Class<?> eventType : dispatchTypes) {
Set<EventHandler> wrappers = getHandlersForEventType(eventType);
if (wrappers != null && !wrappers.isEmpty()) {
dispatched = true;
for (EventHandler wrapper : wrappers) {
enqueueEvent(event, wrapper);
}
}
}