From: Ben Darnell Date: Sun, 2 Aug 2015 20:21:32 +0000 (-0400) Subject: Mention async/await in coroutine docs. X-Git-Tag: v4.3.0b1~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=959da8f6ddd366fccc5b7e2dfbebe3b4f810405f;p=thirdparty%2Ftornado.git Mention async/await in coroutine docs. --- 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 ~~~~~~~~~~~~