CKTIS / Python
anext()
Chiama `__anext__` e restituisce un oggetto da attendere con await.
Versione: Python 3.14; repository image, production runtime not attested
Sintassi
await anext(async_iterator[, default])Chiama __anext__ e restituisce un oggetto da attendere con await.
La prima attesa ottiene 8 dal generatore. Dopo l’esaurimento il valore predefinito fornisce il testo end e ometterlo solleva StopAsyncIteration.
Un None emesso conta come elemento effettivo.
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())
Esempi
import asyncio
async def stream():
yield 8
async def main():
items = stream()
print(await anext(items))
print(await anext(items, "end"))
asyncio.run(main())
Risultato
8 end
Un None emesso conta come elemento effettivo.