Skip to content

Instantly share code, notes, and snippets.

@nhalstead
Created September 5, 2023 16:14
Show Gist options
  • Save nhalstead/fb1be4fb0ca3a42decb008964c21707b to your computer and use it in GitHub Desktop.
Save nhalstead/fb1be4fb0ca3a42decb008964c21707b to your computer and use it in GitHub Desktop.
import asyncio
from asyncio import gather
async def long_process(ith: int):
print(f"foo {ith}")
await asyncio.sleep(2)
print(f"bar {ith}")
return f"result {ith}"
async def main():
(first, second) = await gather(long_process(1), long_process(2))
print(first)
print(second)
if __name__ == '__main__':
asyncio.run(main())
@nhalstead
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment