Znalostní bázeCentrum zkoušek
CSČeština
Vybrat jazyk13

CKTIS / Python

anext()

Zavolá `__anext__` a vrátí objekt, na který lze čekat pomocí await.

Verze: Python 3.14; repository image, production runtime not attested

Syntaxe

await anext(async_iterator[, default])

Zavolá __anext__ a vrátí objekt, na který lze čekat pomocí await.

První čekání získá z generátoru 8. Po vyčerpání dá výchozí hodnota text end, její vynechání vyvolá StopAsyncIteration.

Vydané None je běžným prvkem.

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())

Pří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ýsledek

8
end

Vydané None je běžným prvkem.

Zdroje