b267bef674386ed71505e1bf57c27ca770bb405f
17 """An asynchronous Timer object.
21 timeout: :class:`float`:
22 The duration for which the timer should last.
24 repeat: :class:`bool`:
25 Whether the timer should repeat.
27 callback: :class:`Coroutine` or `Method` or `Function`:
28 An `asyncio` coroutine or a regular method that will be called as soon as
31 callback_args: Optional[:class:`tuple`]:
32 The args to be passed to the callback.
34 callback_kwargs: Optional[:class:`dict`]:
35 The kwargs to be passed to the callback.
37 self
._timeout
= timeout
39 self
._callback
= callback
40 self
._task
= asyncio
.create_task(self
._job
())
41 self
._callback
_args
= callback_args
42 if callback_kwargs
is None:
44 self
._callback
_kwargs
= callback_kwargs
48 while self
._task
.cancelled() is False:
49 await asyncio
.sleep(self
._timeout
)
50 await self
._call
_callback
()
52 await asyncio
.sleep(self
._timeout
)
53 await self
._call
_callback
()
55 async def _call_callback(self
):
56 if asyncio
.iscoroutine(self
._callback
) or asyncio
.iscoroutinefunction(
59 await self
._callback
(*self
._callback
_args
, **self
._callback
_kwargs
)
61 self
._callback
(*self
._callback
_args
, **self
._callback
_kwargs
)
65 Cancels the timer. The callback will not be called.