Continuously execute the provided function with the specified delay. Run the function in a loop, waiting for the configured delay between executions. Supports both synchronous and asynchronous functions.
(self)
| 47 | await self.stop() |
| 48 | |
| 49 | async def _wrapper(self) -> None: |
| 50 | """Continuously execute the provided function with the specified delay. |
| 51 | |
| 52 | Run the function in a loop, waiting for the configured delay between executions. |
| 53 | Supports both synchronous and asynchronous functions. |
| 54 | """ |
| 55 | sleep_time_secs = self.delay.total_seconds() |
| 56 | while True: |
| 57 | await self.func() if inspect.iscoroutinefunction(self.func) else self.func() |
| 58 | await asyncio.sleep(sleep_time_secs) |
| 59 | |
| 60 | def start(self) -> None: |
| 61 | """Start the recurring task execution.""" |