sketchcreate_task schedules; it does not startp5.js
A measured surprise: with two tasks created and a print between, the print runs FIRST. create_task hands the coroutine to the loop and returns immediately -- the coroutine body does not begin until the loop next gets control, which is at your first await. Observed order was: after create_task, start 1, start 2, end 1, end 2.
asyncio.gather
gather is a convenient way to run many coroutines and collect results.
Python
import asyncioasync def job(i: int) -> int: await asyncio.sleep(0.1) return i * iasync def main(): results = await asyncio.gather(*(job(i) for i in range(10))) print(results)asyncio.run(main())
sketchSequential await against gather, with the measured timesp5.js
Ten jobs, each awaiting asyncio.sleep(0.1). Awaiting them one at a time takes the sum; handing them all to asyncio.gather takes about as long as the slowest one. Measured on CPython 3.14.4: 1.091 s sequential against 0.109 s gathered, a 10x difference, and both produce exactly the same list. The bars run in real time -- the animation is not sped up.
Error behavior
If one coroutine fails, gather cancels others by default.