CKTIS / Python
anext()
Appelle `__anext__` et renvoie un objet à attendre avec await.
Version : Python 3.14; repository image, production runtime not attested
Syntaxe
await anext(async_iterator[, default])Appelle __anext__ et renvoie un objet à attendre avec await.
La première attente récupère 8 du générateur. Après épuisement, la valeur par défaut fournit le texte end et son omission lève StopAsyncIteration.
Un None émis reste un élément réel.
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())
Exemples
import asyncio
async def stream():
yield 8
async def main():
items = stream()
print(await anext(items))
print(await anext(items, "end"))
asyncio.run(main())
Résultat
8 end
Un None émis reste un élément réel.