Are Python/ES6 Generators also Coroutines?

My understanding of the generators in Python and ECMAScript is that they are more capable than ordinary generators. For example, both allow for values to passed back into the generator via next() , and they both allow yielding from another generator ( yield from in Python and yield * in ES6), two things that aren't needed in generators.

So, given this extended functionality, are generators as implemented in Python and ES6 for all intents and purposes the same as coroutines? Are there any differences?


From the PEP 380 on yield from :

A Python generator is a form of coroutine, but has the limitation that it can only yield to its immediate caller.

From the python docs on coroutines

A coroutine is a generator that follows certain conventions. For documentation purposes, all coroutines should be decorated with @asyncio.coroutine, but this cannot be strictly enforced.

Generators are a form of limited co-routine. The same should be true for the ES2015 generators.

链接地址: http://www.djcxy.com/p/53240.html

上一篇: 基于协程和本地协程

下一篇: Python / ES6生成器是否也是协程?