From 23394ab9bbc5af55f02af39ec1a6f2f8ef260628 Mon Sep 17 00:00:00 2001 From: David Pastor Date: Wed, 9 Feb 2022 16:08:04 +0100 Subject: [PATCH] Update Watcher re-connection sample. --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9f20166..5be2d56 100644 --- a/README.md +++ b/README.md @@ -585,11 +585,14 @@ void initialize_watcher(const std::string &endpoints, wait_for_connection(client); watcher->reset(new etcd::Watcher(client, prefix, callback)); watcher->Wait([endpoints, prefix, callback, - watcher_ref /* keep the shared_ptr alive */, &watcher](bool cancelled) { + /* watcher reference keep the shared_ptr alive */, &watcher](bool cancelled) -> bool { if (cancelled) { - return; + return false; // No reactivate watcher (default behaviour). } - initialize_watcher(endpoints, prefix, callback, watcher); + + etcd::Client client(endpoints); + wait_for_connection(client); + return true; // Reactivate watcher. }); } ``` @@ -600,7 +603,7 @@ std::function callback = printResponse; const std::string prefix = "/test/key"; // the watcher initialized in this way will auto re-connect to etcd -std::unique_ptr watcher; +std::shared_ptr watcher; initialize_watcher(endpoints, prefix, callback, watcher); ```