#include <userver/concurrent/async_event_source.hpp>
The read-only side of an event channel. Events are delivered to listeners in a strict FIFO order, i.e. only after the event was processed a new event may appear for processing, same listener is never called concurrently.
Definition at line 100 of file async_event_source.hpp.
Public Types | |
using | Function = std::function<void(Args... args)> |
Public Member Functions | |
template<class Class > | |
AsyncEventSubscriberScope | AddListener (Class *obj, std::string_view name, void(Class::*func)(Args...)) |
Subscribes to updates from this event source. | |
AsyncEventSubscriberScope | AddListener (FunctionId id, std::string_view name, Function &&func) |
A type-erased version of AddListener. | |
void | RemoveListener (FunctionId, UnsubscribingKind) noexcept override=0 |
Used by AsyncEventSubscriberScope to cancel an event subscription. | |
Protected Member Functions | |
virtual AsyncEventSubscriberScope | DoAddListener (FunctionId id, std::string_view name, Function &&func)=0 |
using concurrent::AsyncEventSource< Args >::Function = std::function<void(Args... args)> |
Definition at line 102 of file async_event_source.hpp.
|
inline |
Subscribes to updates from this event source.
The listener won't be called immediately. To process the current value and then listen to updates, use UpdateAndListen
of specific event channels.
Example usage:
obj | the subscriber, which is the owner of the listener method, and is also used as the unique identifier of the subscription for this AsyncEventSource |
name | the name of the subscriber, for diagnostic purposes |
func | the listener method, usually called On<DataName>Update , e.g. OnConfigUpdate or OnCacheUpdate |
Unsubscribe
should be called explicitly Definition at line 127 of file async_event_source.hpp.
|
inline |
A type-erased version of AddListener.
id | the unique identifier of the subscription |
name | the name of the subscriber, for diagnostic purposes |
func | the callback used for event notifications |
Definition at line 136 of file async_event_source.hpp.