Allow Timer objects to be cancelled
This commit is contained in:
parent
b692bc7e88
commit
32fa999c78
1 changed files with 5 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue