O'Reilly logo

C++ Reactive Programming by Peter Abraham, Praseed Pai

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The event bus pattern

The event bus acts as a mediator 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 pattern. In an event bus implementation, we have the following:

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

In the implementation that follows, we have omitted the implementation of controllers. The following code implements an event bus:

//----------- EventBus.cpp #include <rxcpp/rx.hpp> #include <memory> #include <map> #include <algorithm> using namespace std; //---------- Event ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required