10 lines
366 B
Python
Executable file
10 lines
366 B
Python
Executable file
class Timer:
|
|
def __init__(self, pubsub, timer_length):
|
|
self.timer_length = timer_length
|
|
self.last_tick = 0
|
|
self.pubsub = pubsub
|
|
self.topic = f"tick {self.timer_length}"
|
|
def tick(self, now):
|
|
if (now - self.last_tick) > self.timer_length:
|
|
self.last_tick = now
|
|
self.pubsub.publish(self.topic, {})
|