pep-492: Add a small example for types.coroutine

This commit is contained in:
Yury Selivanov 2015-06-03 00:08:28 -04:00
parent 12845432a7
commit 7056d7f540
1 changed files with 6 additions and 1 deletions

View File

@ -137,7 +137,12 @@ types.coroutine()
A new function ``coroutine(gen)`` is added to the ``types`` module. It
allows interoperability between existing *generator-based coroutines*
in asyncio and *native coroutines* introduced by this PEP.
in asyncio and *native coroutines* introduced by this PEP::
@types.coroutine
def process_data(db):
data = yield from read_data(db)
...
The function applies ``CO_ITERABLE_COROUTINE`` flag to generator-
function's code object, making it return a *coroutine* object.