|
GNode library (C++)
|
Thread-safe publisher-subscriber event stream. More...
#include <event.hpp>
Classes | |
| struct | Listener |
Public Types | |
| using | callback_t = std::function< void(Args...)> |
| using | listener_id_t = std::size_t |
Public Member Functions | |
| Event ()=default | |
| Event (const Event &)=delete | |
| Event & | operator= (const Event &)=delete |
| Event (Event &&) noexcept=default | |
| Event & | operator= (Event &&) noexcept=default |
| EventConnection | subscribe (callback_t callback) |
| Subscribe to the event. | |
| void | notify (Args... args) |
| Notify all subscribers with the given arguments. | |
Private Member Functions | |
| void | unsubscribe (listener_id_t id) |
Private Attributes | |
| std::vector< Listener > | listeners_ |
| listener_id_t | next_id_ = 0 |
| std::unique_ptr< std::recursive_mutex > | mutex_ |
| std::shared_ptr< void > | alive_token_ = std::make_shared<char>() |
Thread-safe publisher-subscriber event stream.
Allows multiple callbacks to subscribe and receive notifications of new values/signals. It can be notified from another thread than the one that subscribes: once a connection is disconnected, its callback is not called anymore (the disconnection waits for a notification in progress).
| Args | Argument types passed to subscribers when notified. |
| using gnode::Event< Args >::callback_t = std::function<void(Args...)> |
| using gnode::Event< Args >::listener_id_t = std::size_t |
|
default |
|
delete |
|
defaultnoexcept |
|
inline |
Notify all subscribers with the given arguments.
Copies the listener list internally to allow callbacks to safely unsubscribe themselves during execution.
|
delete |
|
defaultnoexcept |
|
inline |
Subscribe to the event.
| callback | Function to be called when notify() is called. |
|
inlineprivate |
|
private |
|
private |
|
private |
|
private |