Skip to content

Instantly share code, notes, and snippets.

@phalt
Created October 19, 2023 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phalt/f03371554bec632687e37cefa7b90b32 to your computer and use it in GitHub Desktop.
Save phalt/f03371554bec632687e37cefa7b90b32 to your computer and use it in GitHub Desktop.
Run async functions together and return them
import asyncio
async def gather_functions(funcs):
tasks = [asyncio.create_task(f) for f in funcs]
return await asyncio.gather(*tasks)
def run(funcs):
"""
Run a list of async functions and return the results.
"""
return asyncio.run(gather_functions(funcs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment