If I try running the following code in Python, I get the following error:
async def foo():
yield 1
async def bar():
x = await foo()
b=bar()
b.send(None)
TypeError: object async_generator can't be used in 'await' expression
On the other hand, the following code works (and throws a StopIteration, but this is expected):
async def foo():
pass
async def bar():
await foo()
b=bar()
b.send(None)
Why doesn't this work?
I can make it work if I replace foo with:
@coroutine
def foo():
yield 1
The problem here is that this seems weird enough that I'm pretty sure this isn't the recommended way of getting this behaviour. Then in most languages you just need async and await, not @coroutine too!