logoalt Hacker News

seabrookmxtoday at 5:57 PM1 replyview on HN

Say I need the results from two expensive REST API calls, so I want to run them concurrently. Managing a thread pool you find a _better_ experience than

one, two = await asyncio.gather(callOne(), callTwo())

?


Replies

wtetznertoday at 9:36 PM

Doesn't Python support futures?

    with ThreadPoolExecutor() as executor:
        one, two = executor.map(lambda f: f(), [callOne, callTwo])
I'm sure you could write a nicer helper function that's more similar to gather as well.