Last active
July 25, 2018 14:30
-
-
Save njsmith/986b0d0e04c3b2bb45de5d662ae873d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def run_all(*async_fns): | |
results = [None] * len(async_fns) | |
async def run_one(i, async_fn): | |
results[i] = await async_fn() | |
async with trio.open_nursery() as nursery: | |
for i, async_fn in enumerate(async_fns): | |
nursery.start_soon(run_one, i, async_fn) | |
return results | |
# Usage: | |
results = await run_all(fn1, fn2) | |
# Or: | |
from functools import partial | |
results = await run_all(partial(fn, arg1, arg2, kw="whatever"), partial(fn, arg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment