aboutsummaryrefslogtreecommitdiff
path: root/chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py
diff options
context:
space:
mode:
Diffstat (limited to 'chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py')
-rw-r--r--chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py b/chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py
new file mode 100644
index 0000000..b10cd98
--- /dev/null
+++ b/chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py
@@ -0,0 +1,15 @@
+class CmRDT:
+ pass
+
+class Counter(CmRDT):
+
+ def __init__(self): # constructor function
+ self._count = 0
+
+ def value(self): # query function
+ return self._count
+
+ def increment(self): # update function
+ self._count += 1
+ for replica in self.replicas():
+ self.transmit("increment", replica)