fabfire_adapter/timer.py

19 lines
411 B
Python
Raw Normal View History

2022-03-16 05:59:18 +01:00
import asyncio
from typing import Callable
import asyncio_mqtt
class Timer:
def __init__(self, timeout: int, callback: Callable):
self._timeout = timeout
self._callback = callback
self._task = asyncio.ensure_future(self._job())
async def _job(self):
await asyncio.sleep(self._timeout)
await self._callback()
def cancel(self):
self._task.cancel()