title: Tornado Async HTTP returning results incrementally
body: <p>From what I understand from tornado.gen module docs is that tornado.gen.Task comprises of tornado.gen.Callback and tornado.gen.Wait with each Callback/Wait pair associated with unique keys ...</p>
  
  <pre><code>  @tornado.web.asynchronous
    @tornado.gen.engine
    def get(self):
        http_client = AsyncHTTPClient()
        http_client.fetch("http://google.com",
                          callback=(yield tornado.gen.Callback("google")))
  
        http_client.fetch("http://python.org",
                          callback=(yield tornado.gen.Callback("python")))
  
        http_client.fetch("http://tornadoweb.org",
                          callback=(yield tornado.gen.Callback("tornado")))
        response = yield [tornado.gen.Wait("google"), tornado.gen.Wait("tornado"), tornado.gen.Wait("python")]
  
        do_something_with_response(response)
        self.render("template.html")
  </code></pre>
  
  <p>So the above code will get all responses from the different URLs.
  Now what I actually need to accomplish is to return the response as soon as one http_client returns the data. So if 'tornadoweb.org' returns the data first, it should do a self.write(respose) and a loop in def get() should keep waiting for other http_clients to complete.
  Any ideas on how to write this using tornado.gen interface.</p>
  
  <p>Very vague implementation(and syntactically incorrect) of what I am trying to do would be like this</p>
  
  <pre><code>class GenAsyncHandler2(tornado.web.RequestHandler):
      @tornado.web.asynchronous
      @tornado.gen.engine
      def get(self):
          http_client = AsyncHTTPClient()
          http_client.fetch("http://google.com",
                            callback=(yield tornado.gen.Callback("google")))
  
          http_client.fetch("http://python.org",
                            callback=(yield tornado.gen.Callback("python")))
  
          http_client.fetch("http://tornadoweb.org",
                            callback=(yield tornado.gen.Callback("tornado")))
  
          while True:
              response = self.get_response()
              if response:
                  self.write(response)
                  self.flush()
              else:
                  break
          self.finish()
  
  
      def get_response(self):
          for key in tornado.gen.availableKeys():
              if key.is_ready:
                  value = tornado.gen.pop(key)
                  return value
          return None
  </code></pre>