I'd like to improve a currently working situation in a more elegant way if there is one.
I need to start a set of long running concurrent tasks with some of them starting with a delay.
So far I'm using gather and made a small wrapper function that wraps the task after an asyncio.sleep
The wrapper is as follows:
async def wrapper(delay, cb, *args, **kwargs):
await asyncio.sleep(delay)
return cb(*args, **kwargs)
And in the main function:
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(
immediate_coroutine(),
wrapper(2.0, wrapped_coroutine)
))
I've found call_later could be useful but it doesn't expect an async function as its callback.
Is there a better way of handling tasks with asyncio for such cases of start delay?