Document the `client.observe()` API.
Resolves #148. Signed-off-by: Tao He <sighingnow@gmail.com>
This commit is contained in:
parent
2f15c45d4e
commit
30c880dd05
23
README.md
23
README.md
|
|
@ -863,14 +863,31 @@ pplx::task<Response> proclaim(std::string const &name, int64_t lease_id,
|
||||||
|
|
||||||
pplx::task<Response> leader(std::string const &name);
|
pplx::task<Response> leader(std::string const &name);
|
||||||
|
|
||||||
std::unique_ptr<Observer> observe(std::string const &name,
|
std::unique_ptr<Observer> observe(std::string const &name);
|
||||||
std::function<void(Response)> callback,
|
|
||||||
const bool once = false);
|
|
||||||
|
|
||||||
pplx::task<Response> resign(std::string const &name, int64_t lease_id,
|
pplx::task<Response> resign(std::string const &name, int64_t lease_id,
|
||||||
std::string const &key, int64_t revision);
|
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<etcd::Observer> 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).
|
for more details, please refer to [etcd/Client.hpp](./etcd/Client.hpp).
|
||||||
|
|
||||||
### TODO
|
### TODO
|
||||||
|
|
|
||||||
|
|
@ -642,7 +642,7 @@ namespace etcd
|
||||||
class Observer {
|
class Observer {
|
||||||
public:
|
public:
|
||||||
~Observer();
|
~Observer();
|
||||||
// wait a at least one response from the observer.
|
// wait at least *one* response from the observer.
|
||||||
Response WaitOnce();
|
Response WaitOnce();
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<etcdv3::AsyncObserveAction> action = nullptr;
|
std::shared_ptr<etcdv3::AsyncObserveAction> action = nullptr;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue