GitHub

StreamAsyncIterator

API reference for StreamAsyncIterator.

One run of a stream, read item by item. aclose() stops it.

Functions

__init__

__init__(chunks, context) -> None
ParameterTypeDescription
chunksStreamChannel[A_co, Any, Any]
contextContext
def __init__(self, chunks: StreamChannel[A_co, Any, Any], context: Context) -> None:
    self._channel = chunks
    self._context = context
    self._scope = CloseableScope()
    self._pull: Effect[tuple[A_co, ...], Any, Any] | None = None
    self._chunk: Iterator[A_co] | None = None
    self._fiber: Fiber[tuple[A_co, ...], Any] | None = None
    self._closing: asyncio.Task[None] | None = None

aclose

aclose() -> None

Interrupt a pull in flight and close the run's scope. Closing again does nothing; __anext__ then ends at once.

async def aclose(self) -> None:
    """Interrupt a pull in flight and close the run's scope. Closing
    again does nothing; ``__anext__`` then ends at once."""
    await self._close(_DONE)

athrow

athrow(error) -> NoReturn

Close the run's scope with error as a defect, then raise error.

ParameterTypeDescription
errorBaseException

Returns NoReturn

async def athrow(self, error: BaseException) -> NoReturn:
    """Close the run's scope with ``error`` as a defect, then raise
    ``error``."""
    await self._close_reporting(die(error))
    raise error