I've been using generator based coroutines before the asyncio
was released.
Now I'm trying to learn the new async/await
features introduced in Python 3.5. This is one of my test programs.
class Await3:
def __init__(self, value):
self.value = value
def __await__(self):
return iter([self.value, self.value, self.value])
async def main_coroutine():
x = await Await3('ABC')
print("x =", x)
def dummy_scheduler(cobj):
snd = None
try:
while True:
aw = cobj.send(snd)
#snd = 42
print("got:", aw)
except StopIteration:
print("stop")
dummy_scheduler(main_coroutine())
Its output is:
got: ABC
got: ABC
got: ABC
x = None
stop
The value of x
is the result of await awaitable_object
expression. Why is this value None
and how can I set it to a value I want?
All I could find is that value of await couroutine()
is determined by the coroutine's return value, but that's not my case.
Uncommenting snd = 42
does not work. The error is AttributeError: 'list_iterator' object has no attribute 'send'