Documentation for yielding dicts

This commit is contained in:
Anton Ryzhov 2013-10-17 19:44:09 +04:00
parent 71c0a9b8b9
commit 15e2812af7
2 changed files with 8 additions and 3 deletions

View 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

View 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`::