![]() |
EduArt Sensor Ring Library 3.0.0
|
Generic thread-safe publisher that manages callback subscriptions. More...
#include <Publisher.hpp>
Public Types | |
| using | Callback = std::function<void(Args...)> |
| Callback type for subscribers. | |
Public Member Functions | |
| Subscription | subscribe (Callback callback) |
| Register a callback. | |
| void | unsubscribe (SubscriberToken token) |
| Remove a previously registered callback. | |
| void | publish (Args... args) const |
| Invoke all registered callbacks with the given arguments. | |
| std::vector< Callback > | copySubscribers () const |
| Copy the current subscriber list under lock. | |
Generic thread-safe publisher that manages callback subscriptions.
Stores subscriber callbacks keyed by SubscriberToken. The publish() method copies the callback list under lock and invokes the copies outside the lock (copy-then-invoke), preventing deadlocks when a callback subscribes or unsubscribes.
| Args | Parameter types forwarded to subscriber callbacks. |
|
inline |
Copy the current subscriber list under lock.
Useful when the caller needs custom exception handling or filtering around the invocation loop.
|
inline |
Invoke all registered callbacks with the given arguments.
Callbacks are copied under lock and invoked outside the lock. Exceptions thrown by callbacks are silently absorbed.
| [in] | args | Arguments forwarded to each callback. |
|
inline |
Register a callback.
| [in] | callback | Invoked on each publish(). |
|
inline |
Remove a previously registered callback.
| [in] | token | Token identifying the subscription to cancel. |