userver: components::DynamicConfig::NoblockSubscriber Class Reference
Loading...
Searching...
No Matches
components::DynamicConfig::NoblockSubscriber Class Referencefinal

#include <userver/dynamic_config/storage/component.hpp>

Detailed Description

Allows to subscribe to DynamicConfig updates without waiting for the first update to complete. Primarily intended for internal use.

Definition at line 94 of file component.hpp.

Public Member Functions

 NoblockSubscriber (DynamicConfig &config_component) noexcept
 
 NoblockSubscriber (NoblockSubscriber &&)=delete
 
NoblockSubscriberoperator= (NoblockSubscriber &&)=delete
 
template<typename Class>
concurrent::AsyncEventSubscriberScope UpdateIfHasConfigAndListen (Class *obj, std::string_view name, void(Class::*func)(const dynamic_config::Diff &diff))
 Subscribes to dynamic-config updates with information about the current and previous states.
 

Member Function Documentation

◆ UpdateIfHasConfigAndListen()

template<typename Class>
concurrent::AsyncEventSubscriberScope components::DynamicConfig::NoblockSubscriber::UpdateIfHasConfigAndListen ( Class * obj,
std::string_view name,
void(Class::* func )(const dynamic_config::Diff &diff) )
inline

Subscribes to dynamic-config updates with information about the current and previous states.

Subscribes to dynamic-config updates using a member function, named OnConfigUpdate by convention. actual configs values are already loaded, also constructs dynamic_config::Diff object using std::nullopt and current config snapshot, then immediately invokes the function with it (this invocation will be executed synchronously).

Note
Callbacks occur in full accordance with components::DynamicConfigClientUpdater options.
Warning
In debug mode the last notification for any subscriber will be called with std::nullopt and current config snapshot.

Example usage:

void OnConfigUpdate(const dynamic_config::Diff& diff_data) {
if (!diff_data.previous) {
return;
}
const auto& previous = *diff_data.previous;
const auto& current = diff_data.current;
if (previous[kBoolConfig] != current[kBoolConfig]) {
OnBoolConfigChanged();
}
if (previous[kDummyConfig].foo != current[kDummyConfig].foo) {
OnFooChanged();
}
}
void OnBoolConfigChanged() { bool_config_change_counter_++; }
void OnFooChanged() { foo_interesting_event_counter_++; }
Parameters
objthe subscriber, which is the owner of the listener method, and is also used as the unique identifier of the subscription
namethe name of the subscriber, for diagnostic purposes
functhe listener method, named OnConfigUpdate by convention.
Returns
a concurrent::AsyncEventSubscriberScope controlling the subscription, which should be stored as a member in the subscriber; Unsubscribe should be called explicitly
See also
based on concurrent::AsyncEventSource engine
dynamic_config::Diff

Definition at line 130 of file component.hpp.


The documentation for this class was generated from the following file: