summaryrefslogtreecommitdiff
path: root/include/erebos/storage.h
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2021-01-17 21:59:46 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2021-01-19 21:44:22 +0100
commit2abd6593c8b047d3fd579aa6cc0058bbebe266f8 (patch)
tree44af7148f648538846ef64bed0f8560f77de7e5d /include/erebos/storage.h
parent1466751256580d8b0e6eea46a8028dcab9742f6b (diff)
Server watching local state head
Diffstat (limited to 'include/erebos/storage.h')
-rw-r--r--include/erebos/storage.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/erebos/storage.h b/include/erebos/storage.h
index 34ed9df..29eaa8f 100644
--- a/include/erebos/storage.h
+++ b/include/erebos/storage.h
@@ -107,6 +107,7 @@ protected:
static UUID storeHead(UUID type, const Ref & ref);
static bool replaceHead(UUID type, UUID id, const Ref & old, const Ref & ref);
static std::optional<Ref> updateHead(UUID type, UUID id, const Ref & old, const std::function<Ref(const Ref &)> &);
+ void watchHead(UUID type, UUID id, const std::function<void(const Ref &)>) const;
};
class Digest
@@ -482,6 +483,7 @@ public:
const Ref & ref() const { return mstored.ref(); }
std::optional<Head<T>> update(const std::function<Stored<T>(const Stored<T> &)> &) const;
+ void watch(const std::function<void(const Head<T> &)> &) const;
private:
UUID mid;
@@ -536,6 +538,14 @@ std::optional<Head<T>> Head<T>::update(const std::function<Stored<T>(const Store
return Head<T>(mid, *res);
}
+template<typename T>
+void Head<T>::watch(const std::function<void(const Head<T> &)> & watcher) const
+{
+ stored().ref().storage().watchHead(T::headTypeId, id(), [id = id(), watcher] (const Ref & ref) {
+ watcher(Head<T>(id, ref));
+ });
+}
+
}
namespace std