Handles routing of an event to multiple listeners. Multiple listeners may attach to the event_router_t by means of operator(). Passing a lambda into operator() attaches to the event.
More...
|
| event_router_t ()=default |
| Construct a new event_router_t object. More...
|
|
| ~event_router_t () |
| Destructor. Will cancel any coroutine awaiting on events. More...
|
|
void | call (const T &event) const |
| Call all attached listeners. Listeners may cancel, by calling the event.cancel method. More...
|
|
bool | empty () const |
| Returns true if the container of listeners is empty, i.e. there is nothing listening for this event right now. More...
|
|
| operator bool () const |
| Returns true if any listeners are attached. More...
|
|
template<typename F > |
event_handle | operator() (F &&fun) |
| Attach a callable to the event, adding a listener. The callable should either be of the form void(const T &) or dpp::job(T) (the latter requires DPP_CORO to be defined), where T is the event type for this event router. More...
|
|
template<typename F > |
event_handle | attach (F &&fun) |
| Attach a callable to the event, adding a listener. The callable should either be of the form void(const T &) or dpp::job(T) (the latter requires DPP_CORO to be defined), where T is the event type for this event router. More...
|
|
bool | detach (const event_handle &handle) |
| Detach a listener from the event using a previously obtained ID. More...
|
|
template<class T>
class dpp::event_router_t< T >
Handles routing of an event to multiple listeners. Multiple listeners may attach to the event_router_t by means of operator(). Passing a lambda into operator() attaches to the event.
Dispatchers of the event may call the call() method to cause all listeners to receive the event.
The empty() method will return true if there are no listeners attached to the event_router_t (this can be used to save time by not constructing objects that nobody will ever see).
The detach() method removes an existing listener from the event, using the event_handle ID returned by operator().
This class is used by the library to route all websocket events to listening code.
Example:
event_router_t<log_t> my_event;
std::cout << cc.message << "\n";
});
log_t lt;
lt.message = "foo";
my_event.call(lt);
my_event.detach(id);
size_t event_handle
A returned event handle for an event which was attached.
Definition: event_router.h:160
- Template Parameters
-