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> ...