aboutsummaryrefslogtreecommitdiff
path: root/chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py
diff options
context:
space:
mode:
Diffstat (limited to 'chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py')
-rw-r--r--chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py b/chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py
new file mode 100644
index 0000000..5182ab1
--- /dev/null
+++ b/chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py
@@ -0,0 +1,20 @@
+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)
+
+ def decrement(self): # update function
+ self._count -= 1
+ for replica in self.replicas():
+ self.transmit("decrement", replica)