aclosing#

class langchain_core.utils.aiter.aclosing(
thing: AsyncGenerator[Any, Any] | AsyncIterator[Any],
)[source]#

Async context manager to wrap an AsyncGenerator that has a aclose() method.

Code like this:

async with aclosing(<module>.fetch(<arguments>)) as agen:
    <block>

is equivalent to this:

agen = <module>.fetch(<arguments>)
try:
    <block>
finally:
    await agen.aclose()

Create the context manager.

Parameters:

thing (AsyncGenerator[Any, Any] | AsyncIterator[Any]) – The resource to wrap.

Methods

__init__(thing)

Create the context manager.

__init__(
thing: AsyncGenerator[Any, Any] | AsyncIterator[Any],
) None[source]#

Create the context manager.

Parameters:

thing (AsyncGenerator[Any, Any] | AsyncIterator[Any]) – The resource to wrap.

Return type:

None