Skip to content

feat: Support flag change notifications. #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/hello-cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ int main() {
LD_LOG(logger, LogLevel::kInfo) << "Got status: " << status;
});

client.FlagNotifier().OnFlagChange(
"my-boolean-flag", [&logger](auto event) {
LD_LOG(logger, LogLevel::kInfo) << "Got flag change: " << *event;
});

client.WaitForReadySync(std::chrono::seconds(30));

auto value = client.BoolVariationDetail("my-bool-flag", false);
auto value = client.BoolVariationDetail("my-boolean-flag", false);
LD_LOG(logger, LogLevel::kInfo) << "Value was: " << *value;
if (auto reason = value.Reason()) {
LD_LOG(logger, LogLevel::kInfo) << "Reason was: " << *reason;
Expand Down
3 changes: 3 additions & 0 deletions libs/client-sdk/include/launchdarkly/client_side/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "launchdarkly/client_side/event_processor.hpp"
#include "launchdarkly/client_side/flag_manager/detail/flag_manager.hpp"
#include "launchdarkly/client_side/flag_manager/detail/flag_updater.hpp"
#include "launchdarkly/client_side/flag_manager/detail/flag_notifier.hpp"
#include "logger.hpp"
#include "value.hpp"

Expand Down Expand Up @@ -74,6 +75,8 @@ class Client {

data_sources::IDataSourceStatusProvider& DataSourceStatus();

flag_manager::detail::IFlagNotifier& FlagNotifier();

void WaitForReadySync(std::chrono::seconds timeout);

~Client();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ class FlagValueChangeEvent {
std::string flag_name_;
};

std::ostream& operator<<(std::ostream& out, FlagValueChangeEvent const& event);

} // namespace launchdarkly::client_side::flag_manager::detail
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "launchdarkly/client_side/connection.hpp"
#include "launchdarkly/client_side/flag_manager/detail/flag_change_event.hpp"
#include "value.hpp"
#include "launchdarkly/client_side/connection.hpp"

namespace launchdarkly::client_side::flag_manager::detail {

Expand Down
4 changes: 4 additions & 0 deletions libs/client-sdk/src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ data_sources::IDataSourceStatusProvider& Client::DataSourceStatus() {
return status_manager_;
}

flag_manager::detail::IFlagNotifier& Client::FlagNotifier() {
return flag_updater_;
}

void Client::WaitForReadySync(std::chrono::seconds timeout) {
std::unique_lock lock(init_mutex_);
init_waiter_.wait_for(lock, timeout, [this] { return initialized_; });
Expand Down
11 changes: 11 additions & 0 deletions libs/client-sdk/src/flag_manager/flag_change_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@ FlagValueChangeEvent::FlagValueChangeEvent(std::string name, Value old_value)
old_value_(std::move(old_value)),
deleted_(true) {}

std::ostream& operator<<(std::ostream& out, FlagValueChangeEvent const& event) {
if (event.Deleted()) {
out << "Event(name: " << event.FlagName() << " deleted)";
} else {
out << "Event(name: " << event.FlagName()
<< ", old value: " << event.OldValue()
<< ", new value: " << event.NewValue() << ")";
}
return out;
}

} // namespace launchdarkly::client_side::flag_manager::detail