timer.py 365 B

12345678910111213141516171819
  1. import asyncio
  2. from elements.element import Element
  3. class Timer:
  4. tasks = []
  5. def __init__(self, interval, callback):
  6. parent = Element.view_stack[-1]
  7. async def loop():
  8. while True:
  9. callback()
  10. await parent.update()
  11. await asyncio.sleep(interval)
  12. self.tasks.append(loop())