Code coordination with EventBus

Using an event bus has great benefits. The main challenge though is how to coordinate code when one component has dependencies on other’s outcome. The ways I found most convenient are:

  1. Use different message types for different steps of the required flow. This means to divide the flow to steps, each section will use its own message type. This way only when step A finishes, it will issue a step B message.
  2. Use ordered delivery and priorities to decide which code runs first.
    Each run code can either:

    1. Cancel the delivery to lower priority handlers.
    2. “Stamp” the event so the decision on how to continue is done on the next handlers. Stamping can be made on real member fields or using a generalized stamping methods by name.
  3. Both 🙂 This means a flow is first divided into main steps using method 1 and then inside each step we can use method 2 to avoid too many message types.

Leave a comment