]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Documentation for yielding dicts 915/head
authorAnton Ryzhov <anton@ryzhov.me>
Thu, 17 Oct 2013 15:44:09 +0000 (19:44 +0400)
committerAnton Ryzhov <anton@ryzhov.me>
Thu, 17 Oct 2013 15:44:09 +0000 (19:44 +0400)
docs/gen.rst
tornado/gen.py

index 28879c0097b23b4937c670a000607471deca6f96..d09a957351aa8045cc3713deafacbd357a3862f9 100644 (file)
@@ -18,7 +18,8 @@
    their result method will be called automatically when they are
    ready.  Additionally, lists of any combination of these objects may
    be yielded; the result is a list of the results of each yield point
-   in the same order.
+   in the same order. Yielding dicts with these objects in values will
+   return dict with results at the same keys.
 
    .. autoclass:: Task
 
index 7eb2c0ca32e1d7273567486a71c9d0407ebf4b86..a363a420364d12bd1e827f14166ac869954b79fd 100644 (file)
@@ -38,8 +38,8 @@ since it is both shorter and provides better exception handling)::
     def get(self):
         yield gen.Task(AsyncHTTPClient().fetch, "http://example.com")
 
-You can also yield a list of ``Futures`` and/or ``Tasks``, which will be
-started at the same time and run in parallel; a list of results will
+You can also yield a list or dict of ``Futures`` and/or ``Tasks``, which will be
+started at the same time and run in parallel; a list or dict of results will
 be returned when they are all finished::
 
     @gen.coroutine
@@ -47,6 +47,10 @@ be returned when they are all finished::
         http_client = AsyncHTTPClient()
         response1, response2 = yield [http_client.fetch(url1),
                                       http_client.fetch(url2)]
+        response_dict = yield dict(response3=http_client.fetch(url3),
+                                   response4=http_client.fetch(url4))
+        response3 = response_dict['response3']
+        response4 = response_dict['response4']
 
 For more complicated interfaces, `Task` can be split into two parts:
 `Callback` and `Wait`::