async def my_func(value: object):
some code
return x
loop = asyncio.get_event_loop()
tasks = []
while True:
task = my_func(some_object)
tasks.append(asyncio.gather(task))
if y == z:
break
................
other code
................
results = loop.run_until_complete(tasks)
loop.close()
async def my_func(value: object):
some code
return x
async def my_func2():
while True:
y = await my_func(some_object)
if y == z:
break
yield y
async def my_func3():
async for i in my_func2():
print(i)