diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2017-02-07 08:27:09 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2017-02-07 08:27:09 (GMT) |
commit | f59286794b49368e48cbcd8b130b4f030f4f80b9 (patch) | |
tree | 07c47d6febd5ab2b42cb2d96fdecdfe4b62f035a /Doc | |
parent | 4e7ff8b1a31ae9c11164940d4171df13b9c1e277 (diff) | |
download | cpython-f59286794b49368e48cbcd8b130b4f030f4f80b9.zip cpython-f59286794b49368e48cbcd8b130b4f030f4f80b9.tar.gz cpython-f59286794b49368e48cbcd8b130b4f030f4f80b9.tar.bz2 |
Issue #29441: Update examples to use async and await keywords in asyncio-task.rst
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/asyncio-task.rst | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index 90cb9c3..558d17c 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -136,17 +136,6 @@ using the :meth:`sleep` function:: loop.run_until_complete(display_date(loop)) loop.close() -The same coroutine implemented using a generator:: - - @asyncio.coroutine - def display_date(loop): - end_time = loop.time() + 5.0 - while True: - print(datetime.datetime.now()) - if (loop.time() + 1.0) >= end_time: - break - yield from asyncio.sleep(1) - .. seealso:: The :ref:`display the current date with call_later() @@ -309,9 +298,8 @@ Example combining a :class:`Future` and a :ref:`coroutine function import asyncio - @asyncio.coroutine - def slow_operation(future): - yield from asyncio.sleep(1) + async def slow_operation(future): + await asyncio.sleep(1) future.set_result('Future is done!') loop = asyncio.get_event_loop() @@ -341,9 +329,8 @@ flow:: import asyncio - @asyncio.coroutine - def slow_operation(future): - yield from asyncio.sleep(1) + async def slow_operation(future): + await asyncio.sleep(1) future.set_result('Future is done!') def got_result(future): |