I want to execute two tasks forever which are run in parallel by asyncio.gather(). The first task contains some logic, for which I want to wait in the while True: loop. The second task is asyncio.sleep() which is responsible for execution of my tasks in equal timestamps. I want to get the result of the first task in asyncio.gather() just after it is finished.
async def main():
async with aiohttp.ClientSession() as session:
while True:
awaitingTime = calcAwaitingTime()
data, _ = await asyncio.gather(BinanceClient.getLastSample(session), asyncio.sleep(awaitingTime))
if __name__ == '__main__':
loop = asyncio.get_event_loop()
task = loop.create_task(main())
loop.run_forever()
I want to get the result of the BinanceClient.getLastSample() just after it is finished not to wait after asyncio.sleep() also is finished. Maybe do you propose other way of executing these two tasks forever to have better possibility to get the results of them?