The Event bus pattern

The Event bus acts as a intermediary between event sources and event sinks. An event source, or producer, emits the events to a bus, and classes that have subscribed to events (consumers) will get notified. The pattern could be an instance of the Mediator design pattern. In an Event bus implementation, we have the following archetypes

  • Producers: Classes which produce events
  • Consumers: Classes which consume events
  • Controllers: Classes which act as producers and consumers

In the implementation that follows, we have omitted the implementation of Controllers. The following code implements a toy version of an Event bus:

//----------- EventBus.cpp #include <rxcpp/rx.hpp> #include <memory> #include <map> #include <algorithm> ...

Get C++ Reactive Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.