diff --git a/README.md b/README.md index bb0ff60..dbd265f 100644 --- a/README.md +++ b/README.md @@ -863,14 +863,31 @@ pplx::task proclaim(std::string const &name, int64_t lease_id, pplx::task leader(std::string const &name); -std::unique_ptr observe(std::string const &name, - std::function callback, - const bool once = false); +std::unique_ptr observe(std::string const &name); pplx::task resign(std::string const &name, int64_t lease_id, std::string const &key, int64_t revision); ``` +The `Observer` returned by `observe()` can be use to monitor the changes of election ownership. +The observer stream will be canceled when been destructed. + +```c++ + std::unique_ptr observer = etcd.observe("test"); + + // wait one change event, blocked execution + etcd::Response resp = observer->WaitOnce(); + + // wait many change events, blocked execution + for (size_t i = 0; i < ...; ++i) { + etcd::Response resp = observer->WaitOnce(); + ... + } + + // cancel the observer + observer.reset(nullptr); +``` + for more details, please refer to [etcd/Client.hpp](./etcd/Client.hpp). ### TODO diff --git a/etcd/SyncClient.hpp b/etcd/SyncClient.hpp index df0a04c..dfcc7da 100644 --- a/etcd/SyncClient.hpp +++ b/etcd/SyncClient.hpp @@ -642,7 +642,7 @@ namespace etcd class Observer { public: ~Observer(); - // wait a at least one response from the observer. + // wait at least *one* response from the observer. Response WaitOnce(); private: std::shared_ptr action = nullptr;