D++ (DPP)
C++ Discord API Bot Library
|
Handles routing of an event to multiple listeners. More...
#include <cluster.h>
Public Member Functions | |
event_router_t () | |
Construct a new event_router_t object. More... | |
void | call (const T &event) const |
Call all attached listeners. Listenrs 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... | |
event_handle | operator() (std::function< void(const T &)> func) |
Attach a lambda to the event, adding a listener. The lambda should follow the signature specified when declaring the event object and should take exactly one parameter derived from event_dispatch_t. More... | |
event_handle | attach (std::function< void(const T &)> func) |
Attach a lambda to the event, adding a listener. The lambda should follow the signature specified when declaring the event object and should take exactly one parameter derived from event_dispatch_t. More... | |
bool | detach (const event_handle &handle) |
Detach a listener from the event using a previously obtained ID. More... | |
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 event_router_t::call() method to cause all listeners to receive the event.
The event_router_t::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 event_router_t::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:
T | type of single parameter passed to event lambda derived from event_dispatch_t |
|
inline |
Construct a new event_router_t object.
|
inline |
Attach a lambda to the event, adding a listener. The lambda should follow the signature specified when declaring the event object and should take exactly one parameter derived from event_dispatch_t.
func | Function lambda to attach to event |
|
inline |
Call all attached listeners. Listenrs may cancel, by calling the event.cancel method.
event | Class to pass as parameter to all listeners. |
|
inline |
Detach a listener from the event using a previously obtained ID.
handle | An ID obtained from event_router_t::operator() |
|
inline |
Returns true if the container of listeners is empty, i.e. there is nothing listening for this event right now.
|
inline |
Attach a lambda to the event, adding a listener. The lambda should follow the signature specified when declaring the event object and should take exactly one parameter derived from event_dispatch_t.
func | Function lambda to attach to event |