Player state
This commit is contained in:
25
hopper/countdown_timer.py
Normal file
25
hopper/countdown_timer.py
Normal file
@ -0,0 +1,25 @@
|
||||
import time
|
||||
from threading import Event, Thread
|
||||
from typing import Callable, Optional
|
||||
|
||||
|
||||
class CountdownTimer(Thread):
|
||||
def __init__(
|
||||
self, seconds: int, callback: Optional[Callable[[], None]] = None
|
||||
) -> None:
|
||||
self.seconds = seconds
|
||||
self.stop_event = Event()
|
||||
self.callback = callback
|
||||
super().__init__()
|
||||
|
||||
def run(self) -> None:
|
||||
cnt = self.seconds
|
||||
while cnt > 0 and not self.stop_event.is_set():
|
||||
cnt -= 1
|
||||
time.sleep(1)
|
||||
|
||||
if cnt == 0 and self.callback:
|
||||
self.callback()
|
||||
|
||||
def stop(self) -> None:
|
||||
self.stop_event.set()
|
||||
Reference in New Issue
Block a user