Skip to content

Instantly share code, notes, and snippets.

@njsmith
Last active July 25, 2018 14:30
Show Gist options
  • Save njsmith/986b0d0e04c3b2bb45de5d662ae873d5 to your computer and use it in GitHub Desktop.
Save njsmith/986b0d0e04c3b2bb45de5d662ae873d5 to your computer and use it in GitHub Desktop.
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