title: async / await: Continuously stream data from async method
body: <p>I'm using python 3.5 to asynchronously return data from one method to another as follows:</p>
  
  <pre><code>async def A():
      # Need to get data here from B continuously
      val = await B()
  
  async def B():
      # Need to get data here from C continuously as they get generated inside while loop of method C
      data = await C()
      # Modify and process the data and return to A
      return await D(data)
  
  async def C():
      i = 0
      while i &lt; 5:
          await asyncio.sleep(1)
          # Return this data to method B one by one, Not sure how to do this ??
          return i
  
  async def D(val):
      # Do some processing of val and return it
      return val
  </code></pre>
  
  <p>I want to continuously stream data from method C and return it to method B, process each item as they are received and return it to method A.</p>
  
  <p>One way is use an <code>asyncio queue</code> and pass it to method B from A, from where it further gets passed on to C.</p>
  
  <ol>
  <li>Method C would keep writing the content in the queue.</li>
  <li>Method B would read from queue, process the data and update the queue.</li>
  <li>Method A reads the queue at the end for finally processed data.</li>
  </ol>
  
  <p>Can we achieve it using coroutines or async method itself in any other way ? Wish to avoid calls for reading and writing to queues continuously for every request.</p>