title: Python asyncio - How to chain() the results returned from as_completed() lazily?
body: <p>In the following code example I need to find a solution for Step 3):</p>
  
  <pre class="lang-python prettyprint-override"><code>import asyncio as aio
  import random
  
  
  async def produce_numbers(x):
      await aio.sleep(random.uniform(0, 3.0))
      return [x * x, x * x + 1, x * x + 2]
  
  
  async def main():
  
      # Step 1) Create a list of unawaited coroutines.
      coros = [produce_numbers(i) for i in range(0, 10)]
  
      # Step 2) Create generator to return items in order of completion.
      futs = aio.as_completed(coros)  # type: generator
  
      # Step 3) Create a generator that returns every single number lazily.
      # This is the step I don't know how to accomplish.
      # I can't find a way to chain the lists that I get from each
      # `produce_numbers()` call together in a lazy manner.
  
      # Step 4) This loops should fire as soon as the first
      # `produce_numbers()` coroutine finished.
      for number in my_number_generator:
          print(number)
  
  
  if __name__ == '__main__':
      loop = aio.get_event_loop()
      loop.run_until_complete(main())
  </code></pre>
  
  <p>Perhaps there is a crucial function in the standard lib that I'm missing?</p>