CKTIS / Python
aiter()
Získa asynchrónny iterátor pomocou `__aiter__` bez čakania na hodnotu.
Verzia: Python 3.14; repository image, production runtime not attested
Syntax
aiter(async_iterable, /)Získa asynchrónny iterátor pomocou __aiter__ bez čakania na hodnotu.
Generátor vráti sám seba a test totožnosti dá True. Až await anext načíta 7 a aclose generátor uzavrie.
Bežný zoznam tento protokol nepodporuje.
import asyncio
async def gen():
yield 7
async def check():
g = gen()
assert aiter(g) is g and await anext(g) == 7
await g.aclose()
asyncio.run(check())
Príklady
import asyncio
async def stream():
yield 7
async def main():
items = aiter(stream())
print(aiter(items) is items)
print(await anext(items))
await items.aclose()
asyncio.run(main())
Výsledok
True 7
Bežný zoznam tento protokol nepodporuje.