Documentation for yielding dicts
This commit is contained in:
parent
71c0a9b8b9
commit
15e2812af7
|
@ -18,7 +18,8 @@
|
||||||
their result method will be called automatically when they are
|
their result method will be called automatically when they are
|
||||||
ready. Additionally, lists of any combination of these objects may
|
ready. Additionally, lists of any combination of these objects may
|
||||||
be yielded; the result is a list of the results of each yield point
|
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
|
.. autoclass:: Task
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,8 @@ since it is both shorter and provides better exception handling)::
|
||||||
def get(self):
|
def get(self):
|
||||||
yield gen.Task(AsyncHTTPClient().fetch, "http://example.com")
|
yield gen.Task(AsyncHTTPClient().fetch, "http://example.com")
|
||||||
|
|
||||||
You can also yield a list of ``Futures`` and/or ``Tasks``, which will be
|
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 of results will
|
started at the same time and run in parallel; a list or dict of results will
|
||||||
be returned when they are all finished::
|
be returned when they are all finished::
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
|
@ -47,6 +47,10 @@ be returned when they are all finished::
|
||||||
http_client = AsyncHTTPClient()
|
http_client = AsyncHTTPClient()
|
||||||
response1, response2 = yield [http_client.fetch(url1),
|
response1, response2 = yield [http_client.fetch(url1),
|
||||||
http_client.fetch(url2)]
|
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:
|
For more complicated interfaces, `Task` can be split into two parts:
|
||||||
`Callback` and `Wait`::
|
`Callback` and `Wait`::
|
||||||
|
|
Loading…
Reference in New Issue