]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Mention async/await in coroutine docs.
authorBen Darnell <ben@bendarnell.com>
Sun, 2 Aug 2015 20:21:32 +0000 (16:21 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 2 Aug 2015 20:24:48 +0000 (16:24 -0400)
docs/guide/coroutines.rst

index f5932e7623c04c7b1ba74e3c5c90f69cb9123e7a..8dc0b9dd13d5e471335b28630970a01e50019a45 100644 (file)
@@ -33,6 +33,22 @@ Example::
         # instead.
         return response.body
 
+Python 3.5: ``async`` and ``await``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Python 3.5 introduces the ``async`` and ``await`` keywords. Starting in
+Tornado 4.3, you can use them in place of ``yield``-based coroutines.
+Simply use ``async def foo()`` in place of a function definition with the
+``@gen.coroutine`` decorator, and ``await`` in place of yield. The rest of
+this document still uses the ``yield`` style for compatibility with older
+versions of Python, but ``async`` and ``await`` will run faster when they
+are available::
+
+    async def fetch_coroutine(url):
+        http_client = AsyncHTTPClient()
+        response = await http_client.fetch(url)
+        return response.body
+
 How it works
 ~~~~~~~~~~~~