diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-11-14 21:36:14 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-11-14 21:36:14 +0100 |
commit | 14d6b6f7e4876b897592812475f201a01084c13d (patch) | |
tree | beb8f734040239e0171232be474a29349c0e3944 /src | |
parent | 7297ec818dae9c86b1f614743129553242cf23b6 (diff) |
Test: get and wait for shared state
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index dad307c..387fe4a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -306,6 +306,44 @@ void stopServer(const vector<string> &) server.reset(); } +void sharedStateGet(const vector<string> &) +{ + ostringstream ss; + ss << "shared-state-get"; + for (const auto & r : h->behavior().lens<vector<Ref>>().get()) + ss << " " << string(r.digest()); + printLine(ss.str()); +} + +void sharedStateWait(const vector<string> & args) +{ + static optional<Watched<vector<Ref>>> watched; + watched = h->behavior().lens<vector<Ref>>().watch([args, watched = watched] (const vector<Ref> & refs) mutable { + vector<Stored<Object>> objs; + objs.reserve(refs.size()); + for (const auto & r : refs) + objs.push_back(Stored<Object>::load(r)); + + auto objs2 = objs; + for (const auto & a : args) + if (auto ref = st.ref(Digest(a))) + objs2.push_back(Stored<Object>::load(*ref)); + else + return; + + filterAncestors(objs2); + if (objs2 == objs) { + ostringstream ss; + ss << "shared-state-wait"; + for (const auto & a : args) + ss << " " << a; + printLine(ss.str()); + + watched = std::nullopt; + } + }); +} + void watchLocalIdentity(const vector<string> &) { auto bhv = h->behavior().lens<optional<Identity>>(); @@ -395,6 +433,8 @@ vector<Command> commands = { { "create-identity", createIdentity }, { "start-server", startServer }, { "stop-server", stopServer }, + { "shared-state-get", sharedStateGet }, + { "shared-state-wait", sharedStateWait }, { "watch-local-identity", watchLocalIdentity }, { "watch-shared-identity", watchSharedIdentity }, { "update-local-identity", updateLocalIdentity }, |