CKTIS / Python
aiter()
Získá asynchronní iterátor pomocí `__aiter__` bez čekání na hodnotu.
Verze: Python 3.14; repository image, production runtime not attested
Syntaxe
aiter(async_iterable, /)Získá asynchronní iterátor pomocí __aiter__ bez čekání na hodnotu.
Generátor vrátí sám sebe a test totožnosti dá True. Teprve await anext načte 7 a aclose generátor uzavře.
Běžný seznam 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())
Pří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ýsledek
True 7
Běžný seznam tento protokol nepodporuje.