Yaron Levi
10/19/2023, 10:06 PMfutures = [call_onesignal_api.submit(body=body,url=url, method='POST', app_type=app_type) for body in bodies]
But then I want to add some code to check the results of those tasks so I can know if some failed:
futures = [call_onesignal_api.submit(body=body,url=url, method='POST', app_type=app_type) for body in bodies]
results = [future.result() for future in futures]
But adding this line causes the tasks to run one by one and not concurrently.
How can I run the tasks concurrently, but get the results of them once they all finished?
Thanks.Kevin Grismore
10/19/2023, 10:38 PMfrom prefect import flow, task
import asyncio
@flow
async def my_flow():
names = ['Kevin', 'Yaron']
futures = await asyncio.gather(*[say_hello.submit(name) for name in names])
print([await future.result() for future in futures])
@task
async def say_hello(name: str):
return f'Hello {name}!'
if __name__=='__main__':
asyncio.run(my_flow())
Yaron Levi
10/19/2023, 11:25 PMYaron Levi
10/19/2023, 11:26 PMresults = [future.result() for future in futures]
To this:
results = [future.wait() for future in futures]