aboutsummaryrefslogtreecommitdiff
path: root/chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py
blob: 5182ab1e11b9a0d5c1ed3d5139f35b135d7c7eaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)