From 959da8f6ddd366fccc5b7e2dfbebe3b4f810405f Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 2 Aug 2015 16:21:32 -0400 Subject: [PATCH] Mention async/await in coroutine docs. --- docs/guide/coroutines.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/guide/coroutines.rst b/docs/guide/coroutines.rst index f5932e762..8dc0b9dd1 100644 --- a/docs/guide/coroutines.rst +++ b/docs/guide/coroutines.rst @@ -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 ~~~~~~~~~~~~ -- 2.47.2