(*, callback, timedelta: datetime.timedelta, also_run_immediately: bool)
Call callback every timedelta

    If also_run_immediately is set then the callback will be called before any waiting
    happens. If the callback's result is awaitable then it will be awaited

    Callback execution time is accounted for in the scheduling. If the execution takes
    2 seconds, and timedelta is 10 seconds, then call_every() will wait 8 seconds
    before the subsequent execution.
Call callback every timedelta
Call callback every timedelta
async def call_every(*, callback, timedelta: datetime.timedelta, also_run_immediately: bool):
    """Call callback every timedelta

    If also_run_immediately is set then the callback will be called before any waiting
    happens. If the callback's result is awaitable then it will be awaited

    Callback execution time is accounted for in the scheduling. If the execution takes
    2 seconds, and timedelta is 10 seconds, then call_every() will wait 8 seconds
    before the subsequent execution.
    """
    first_run = True
    while True:
        start_time = time()
        if not first_run or also_run_immediately:
            await run_user_provided_callable(callback, args=[], kwargs={})
        total_execution_time = time() - start_time
        sleep_time = max(0.0, timedelta.total_seconds() - total_execution_time)
        await asyncio.sleep(sleep_time)
        first_run = False
async def call_every ( * , callback , timedelta : datetime . timedelta , also_run_immediately : bool ) : first_run = True while True : start_time = time ( ) if not first_run or also_run_immediately : await run_user_provided_callable ( callback , args = [ ] , kwargs = { } ) total_execution_time = time ( ) - start_time sleep_time = max ( 0.0 , timedelta . total_seconds ( ) - total_execution_time ) await asyncio . sleep ( sleep_time ) first_run = False