There seem to be two kinds of generator-based coroutine:
From a reply by Jim Fasarakis Hilliard:
Generator-based coroutine: A generator (
def
+yield
) that is wrapped bytypes.coroutine
. You need to wrap it intypes.coroutine
if you need it to be considered a coroutine object.From Python in a Nutshell, which doesn't explicitly call it "generator-based coroutine":
When you write Python code based on
asyncio
(ideally also using add-on modules from asyncio.org), you’ll usually be writing coroutine functions. Up to Python 3.4 included, such functions are generators using theyield from
statement covered in “yield from (v3-only)” on page 95, decorated with@asyncio.coroutine
, covered in “asyncio coroutines” on page 518;From https://www.python.org/dev/peps/pep-0492/#differences-from-generators
generator-based coroutines (for asyncio code must be decorated with @asyncio.coroutine)
http://masnun.com/2015/11/13/python-generators-coroutines-native-coroutines-and-async-await.html also calls it "generator-based coroutine".
Are the two kinds of generator-based coroutines the same concept?
If not, what are their differences in purposes and usages?
Thanks.