CKTIS / Python
anext()
Pokliče `__anext__` in vrne objekt, na katerega lahko čakamo z await.
Različica: Python 3.14; repository image, production runtime not attested
Sintaksa
await anext(async_iterator[, default])Pokliče __anext__ in vrne objekt, na katerega lahko čakamo z await.
Prvo čakanje pridobi 8 iz generatorja. Po izčrpanju privzeta vrednost da besedilo end, njena opustitev pa sproži StopAsyncIteration.
Oddani None je navaden element.
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())
Primeri
import asyncio
async def stream():
yield 8
async def main():
items = stream()
print(await anext(items))
print(await anext(items, "end"))
asyncio.run(main())
Rezultat
8 end
Oddani None je navaden element.