Send player info with product purchase data
This commit is contained in:
@ -5,21 +5,24 @@ from typing import Callable, Optional
|
||||
|
||||
class CountdownTimer(Thread):
|
||||
def __init__(
|
||||
self, seconds: int, callback: Optional[Callable[[], None]] = None
|
||||
self, seconds: int, timer_tick_callback: Optional[Callable[[int], None]] = None, timer_done_callback: Optional[Callable[[], None]] = None
|
||||
) -> None:
|
||||
self.seconds = seconds
|
||||
self.stop_event = Event()
|
||||
self.callback = callback
|
||||
self.timer_tick_callback = timer_tick_callback
|
||||
self.timer_done_callback = timer_done_callback
|
||||
super().__init__(daemon=True)
|
||||
|
||||
def run(self) -> None:
|
||||
cnt = self.seconds
|
||||
while cnt and not self.stop_event.is_set():
|
||||
cnt -= 1
|
||||
time_left = self.seconds
|
||||
while time_left and not self.stop_event.is_set():
|
||||
time.sleep(1)
|
||||
time_left -= 1
|
||||
if self.timer_tick_callback:
|
||||
self.timer_tick_callback(time_left)
|
||||
|
||||
if cnt == 0 and self.callback:
|
||||
self.callback()
|
||||
if time_left == 0 and self.timer_done_callback:
|
||||
self.timer_done_callback()
|
||||
|
||||
def stop(self) -> None:
|
||||
self.stop_event.set()
|
||||
|
||||
Reference in New Issue
Block a user