Allow Timer objects to be cancelled

This commit is contained in:
jesopo 2019-07-09 11:14:05 +01:00
parent b692bc7e88
commit 32fa999c78

View file

@ -18,7 +18,7 @@ class Timer(object):
def set_next_due(self):
self.next_due = time.time()+self.delay
def due(self) -> bool:
return self.time_left() <= 0
return not self.done() and self.time_left() <= 0
def time_left(self) -> float:
return self.next_due-time.time()
@ -27,6 +27,8 @@ class Timer(object):
self.set_next_due()
def finish(self):
self._done = True
def cancel(self):
self.finish()
def done(self) -> bool:
return self._done