CKTIS / Python
aiter()
Obtém um iterador assíncrono por `__aiter__` sem aguardar um valor.
Versão: Python 3.14; repository image, production runtime not attested
Sintaxe
aiter(async_iterable, /)Obtém um iterador assíncrono por __aiter__ sem aguardar um valor.
O gerador devolve-se a si próprio e o teste de identidade dá True. Só await anext obtém 7 e aclose fecha o gerador.
Uma lista normal não suporta este protocolo.
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())
Exemplos
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())
Resultado
True 7
Uma lista normal não suporta este protocolo.