2016-04-13 15:27:06 +01:00
|
|
|
# test basic async for execution
|
|
|
|
# example taken from PEP0492
|
|
|
|
|
|
|
|
class AsyncIteratorWrapper:
|
|
|
|
def __init__(self, obj):
|
|
|
|
print('init')
|
|
|
|
self._it = iter(obj)
|
|
|
|
|
2020-07-21 18:47:28 +01:00
|
|
|
def __aiter__(self):
|
2016-04-13 15:27:06 +01:00
|
|
|
print('aiter')
|
|
|
|
return self
|
|
|
|
|
|
|
|
async def __anext__(self):
|
|
|
|
print('anext')
|
|
|
|
try:
|
|
|
|
value = next(self._it)
|
|
|
|
except StopIteration:
|
|
|
|
raise StopAsyncIteration
|
|
|
|
return value
|
|
|
|
|
|
|
|
async def coro():
|
|
|
|
async for letter in AsyncIteratorWrapper('abc'):
|
|
|
|
print(letter)
|
|
|
|
|
|
|
|
o = coro()
|
|
|
|
try:
|
|
|
|
o.send(None)
|
|
|
|
except StopIteration:
|
|
|
|
print('finished')
|