CKTIS / Python
anext()
Invoca `__anext__` y devuelve un objeto que se espera con await.
Versión: Python 3.14; repository image, production runtime not attested
Sintaxis
await anext(async_iterator[, default])Invoca __anext__ y devuelve un objeto que se espera con await.
La primera espera obtiene 8 del generador. Al agotarse, el valor predeterminado proporciona el texto end y omitirlo provoca StopAsyncIteration.
Un None emitido cuenta como elemento real.
import asyncio
async def gen():
yield None
async def check():
g = gen()
assert await anext(g, 9) is None
assert await anext(g, 9) == 9
asyncio.run(check())
Ejemplos
import asyncio
async def stream():
yield 8
async def main():
items = stream()
print(await anext(items))
print(await anext(items, "end"))
asyncio.run(main())
Resultado
8 end
Un None emitido cuenta como elemento real.