Consider this simple coroutine
In [9]: async def coro():
...: print('hello world')
...:
We know that that native coroutines are not iterators
In [12]: type(c)
Out[12]: coroutine
In [13]: next(c)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-13-e846efec376d> in <module>()
----> 1 next(c)
TypeError: 'coroutine' object is not an iterator
However, if I run a coroutine, I get a StopIteration
error.
In [10]: c = coro()
In [11]: c.send(None)
hello world
---------------------------
StopIteration Traceback (most recent call last)
<ipython-input-11-d9162d5dda48> in <module>()
----> 1 c.send(None)
StopIteration:
this answers that native co-routines are functionally equivalent to generated based coroutines. But another answer for the same question goes further and explains how they serve separate purposes as well.
Is the only reason that native coros raise StopIteration
error is that they share significant code with generator based coros? or there is some other reason as well?