The anext()
function is used to advance an asynchronous iterator by one step. It returns the next item of an asynchronous iterator or raises the StopAsyncIteration
exception if the iterator is exhausted.
Parameter Values
Parameter | Description |
---|---|
async_iterator |
|
Return Values
The anext()
function returns the next item from an async iterator.
How to Use anext()
in Python
Example 1:
The anext()
function retrieves the next available item from an asynchronous iterator.
async def async_generator():
yield 1
yield 2
async_iter = async_generator().__aiter__()
next_item = await anext(async_iter)
print(next_item)