lordmauve / wasabi2d

Cutting-edge 2D game framework for Python
https://wasabi2d.readthedocs.io/
GNU Lesser General Public License v3.0
154 stars 24 forks source link

Add gather() for coroutines #42

Open lordmauve opened 4 years ago

lordmauve commented 4 years ago

asyncio.gather() is a function for awaiting several coroutines at once.

Users should be able to write something not dissimilar to

await gather(
    some_coro(),
    another_coro()
)

Perhaps related, the task object returned by clock.coro.run() should have an async def join() so that you can await it finishing:

task = clock.coro.run(...)

await task.join()

This can be used to implement gather:

async def gather(*coros, clock=None):
    clock = clock or get_my_clock()
    tasks = [clock.coro.run(t) for t in coros]
    for t in tasks:
        await t.join()