|
ORE Studio 0.0.4
|
A typed, thread-safe, in-process publish/subscribe event bus. More...
#include <event_bus.hpp>

Public Member Functions | |
| event_bus (const event_bus &)=delete | |
| event_bus & | operator= (const event_bus &)=delete |
| event_bus (event_bus &&)=delete | |
| event_bus & | operator= (event_bus &&)=delete |
| template<typename Event > | |
| subscription | subscribe (std::function< void(const Event &)> handler) |
| Subscribe to events of a specific type. | |
| template<typename Event > | |
| void | publish (const Event &event) |
| Publish an event to all subscribers. | |
| template<typename Event > | |
| std::size_t | subscriber_count () const |
| Get the number of subscribers for a specific event type. | |
A typed, thread-safe, in-process publish/subscribe event bus.
The event bus provides a decoupled communication mechanism between components. Publishers emit events without knowing who subscribes, and subscribers receive events without knowing who publishes them.
Thread Safety:
Usage:
| subscription subscribe | ( | std::function< void(const Event &)> | handler | ) |
Subscribe to events of a specific type.
| Event | The event type to subscribe to. |
| handler | The callback function to invoke when an event is published. |
| void publish | ( | const Event & | event | ) |
Publish an event to all subscribers.
| Event | The event type being published. |
| event | The event instance to publish. |
All registered handlers for this event type will be invoked synchronously. Exceptions thrown by handlers are caught and logged, but do not prevent other handlers from being called.

| std::size_t subscriber_count | ( | ) | const |
Get the number of subscribers for a specific event type.
| Event | The event type to query. |