Asyncio - gathering task data within the loop (example/feedback request)


#1

I am pretty new to asyncio, but apistar derives from most of the examples because any function you make is already running in side a loop. I spent half a day researching and I couldn’t find a good documentation on how to run tasks and gather the results if you’re already have a main loop running. Finally, I got this one example working pretty well. It spits off about 19 jobs, each sleeps a random time from 1-5 seconds. Then we wait for all tasks to complete, and I can gather those results into a single result which gets returned.

If there is a better way to approach this, I’d love to hear it. Perhaps some feature of asyncio or apistar internals I’m missing, or a more robust python module that people use.