Mixing Native & Generator Based Coroutines
Explore the differences between native and generator-based coroutines in Python and learn how decorators like @asyncio.coroutine and @types.coroutine enable their compatibility. Understand backward compatibility issues and how to await generator-based coroutines in native async code using asyncio.
We'll cover the following...
Mixing Native & Generator Based Coroutines
In order to maintain backward compatibility, generator-based coroutines can work with native coroutines by using appropriate decorators. In this lesson, we first look at the differences between the two types of coroutines and then examine the decorators that can be used to make the two work with each other.
Native Coroutines vs Generator-based Coroutines
Generator based coroutines and native coroutines have differences between themselves which are listed below:
Native coroutines don't implement the
__iter__()and__next__()methods and therefore can't be iterated upon.Generator based coroutines can't
yield froma native ...