Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eventbus event order

Morning,

I'm using the SimpleEvent bus to send data from my centralized data reviver to the Widgets. This works really fine, I get one set of new Data form the server, the success method of the RPC call puts it on the Eventbus, each widget looks if the data is for it, if yes it 'displays' it, if not, it does nothing.There is only one data set per request and the widgets don't depend on other data being already sent.

Now I have a Tree widget. The child nodes of the Tree are created throw this data sets too, and this child nodes register itself to the Eventbus to revive the data for their child nodes. The data shall be received in on rush (for performance reasons obv), so I will get multiple data sets which are put on the Eventbus at the 'same time' (in a for loop). I only control the order in which they are put there (first the root, then the data for the first child......). How does the Eventbus now proceeds the events?

  • Does he wait till the first event is completed, so the first child of the tree already finished creation and register itself to the Eventbus, to revive the data to create it's child's.
  • Does he handle them simultaneous, so a widget isn't even registered to the Eventbus.
  • Does he mix up the order?!?!

Current solution approaches:

  1. The best solution I can think of, is to only put new events on the Eventbus when the previous got completed. However I found a method which does so, or if it is the standard behavior of the Eventbus .
  2. Fire a request processing finished event, when a event was processed by a widget. Yucks... this leads to a lot of additional code and causes big problems, when data is put on the Eventbus which doesn't belong to any widget....
  3. Register a static variable which is set to true when the request got handled and the Eventbus waits this long till he puts the next request on the Eventbus (Quiet similar to two, but way worse coding style and the same problems)
  4. All events are handled by the root tree element, which sends them upwards to the respective child's.

Which solution would you prefer and why?

Regards, Stefan

PS: my favorite answer would be that 1. is the standard behavior of the Eventbus^^ PPS: The solution should also be working on when introducing Webworkers.

like image 741
Stefan Avatar asked Dec 28 '22 11:12

Stefan


1 Answers

The EventBus#fireEvent is synchronous. It's by design. You can pass an event to the bus, have handlers possibly modify it, and when execution returns to your method you can check the event; this is used for PlaceChangeRequestEvent and its setMessage for instance.

FYI, if a handler throws an exception, it won't prevent other handlers from being executed. The fireEvent will then wrap the exceptions (plural; several handlers can throw) in an UmbrellaException.

like image 58
Thomas Broyer Avatar answered Jan 04 '23 07:01

Thomas Broyer