CKTIS / Python
anext()
Zavolá `__anext__` a vráti objekt, na ktorý možno čakať pomocou await.
Verzia: Python 3.14; repository image, production runtime not attested
Syntax
await anext(async_iterator[, default])Zavolá __anext__ a vráti objekt, na ktorý možno čakať pomocou await.
Prvé čakanie získa z generátora 8. Po vyčerpaní dá predvolená hodnota text end, jej vynechanie vyvolá StopAsyncIteration.
Vydané None je bežným prvkom.
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())
Príklady
import asyncio
async def stream():
yield 8
async def main():
items = stream()
print(await anext(items))
print(await anext(items, "end"))
asyncio.run(main())
Výsledok
8 end
Vydané None je bežným prvkom.