Added timer class
This commit is contained in:
26
functions/timer.py
Normal file
26
functions/timer.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import asyncio
|
||||
|
||||
class Timer():
|
||||
def __init__(self, minutes, seconds):
|
||||
self.minutes = minutes
|
||||
self.seconds = seconds
|
||||
self.ended = True
|
||||
|
||||
def start(self):
|
||||
self.ended = False
|
||||
self.timer_task = asyncio.ensure_future(self.update())
|
||||
|
||||
def stop(self):
|
||||
self.timer_task.cancel()
|
||||
self.endend = True
|
||||
|
||||
async def update(self):
|
||||
while self.ended == False:
|
||||
await asyncio.sleep(1)
|
||||
if (self.minutes > 0 and self.seconds == 0):
|
||||
self.minutes -= 1
|
||||
self.seconds = 59
|
||||
elif (self.seconds > 0):
|
||||
self.seconds -= 1
|
||||
if (self.minutes == 0 and self.seconds == 0):
|
||||
self.ended = True
|
||||
Reference in New Issue
Block a user