Giter VIP home page Giter VIP logo

Comments (2)

danielzhanghl avatar danielzhanghl commented on July 25, 2024

after some dig into the code, it seems the watch can not be cancelled, that is a bug.

from etcd-cpp-apiv3.

sighingnow avatar sighingnow commented on July 25, 2024

Hi @danielzhanghl,

You could find sync-watch examples in

TEST_CASE("wait for a value change")
{
etcd::SyncClient etcd(etcd_uri);
etcd.set("/test/key1", "42");
std::thread watch_thrd([&]() {
etcd::Response res = etcd.watch("/test/key1");
REQUIRE("set" == res.action());
CHECK("43" == res.value().as_string());
});
sleep(1);
etcd.set("/test/key1", "43");
watch_thrd.join();
REQUIRE(0 == etcd.rmdir("/test", true).error_code());
}
TEST_CASE("wait for a directory change")
{
etcd::SyncClient etcd(etcd_uri);
std::thread watch_thrd1([&]() {
etcd::Response res = etcd.watch("/test", true);
CHECK("create" == res.action());
CHECK("44" == res.value().as_string());
});
sleep(1);
etcd.add("/test/key4", "44");
watch_thrd1.join();
std::thread watch_thrd2([&]() {
etcd::Response res2 = etcd.watch("/test", true);
CHECK("set" == res2.action());
CHECK("45" == res2.value().as_string());
});
sleep(1);
etcd.set("/test/key4", "45");
watch_thrd2.join();
REQUIRE(0 == etcd.rmdir("/test", true).error_code());
}
TEST_CASE("watch changes in the past")
{
etcd::SyncClient etcd(etcd_uri);
int index = etcd.set("/test/key1", "42").index();
etcd.set("/test/key1", "43");
etcd.set("/test/key1", "44");
etcd.set("/test/key1", "45");
etcd::Response res = etcd.watch("/test/key1", ++index);
CHECK("set" == res.action());
CHECK("43" == res.value().as_string());
res = etcd.watch("/test/key1", ++index);
CHECK("set" == res.action());
CHECK("44" == res.value().as_string());
res = etcd.watch("/test", ++index, true);
CHECK("set" == res.action());
CHECK("45" == res.value().as_string());
REQUIRE(0 == etcd.rmdir("/test", true).error_code());
}
.

from etcd-cpp-apiv3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.