Hi :wave: When submitting this array of http call...
# ask-community
y
Hi 👋 When submitting this array of http calls, everything is nice and they run concurrently:
Copy code
futures = [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:
Copy code
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.
k
I was able to get this working:
Copy code
from 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())
y
@Kevin Grismore Thanks for the help! But I found what was the problem.
Changed this:
Copy code
results = [future.result() for future in futures]
To this:
Copy code
results = [future.wait() for future in futures]