Skip to content

AsyncIterableStream<T>

Namespace: Vercel.AI.Util

public sealed class AsyncIterableStream<T> : IAsyncEnumerable<T>

A readable stream that can also be enumerated with await foreach.

Type parameters

Name Description
T

Inheritance: object

Implements: IAsyncEnumerable<T>

View source

public AsyncIterableStream(ReadableStream<T> stream)

Creates an iterable view of <code class=“paramref”>stream</code>.

Parameters

Name Type Description
stream ReadableStream&lt;T&gt;

View source

public bool Locked { get; }

Whether a reader holds the lock.

Value: bool

View source

public ReadableStream<T> Stream { get; }

Underlying stream.

Value: ReadableStream&lt;T&gt;

View source

public Task CancelAsync()

Cancels the stream.

Returns: Task

View source

public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)

Returns an enumerator that iterates asynchronously through the collection.

Parameters

Name Type Description
cancellationToken CancellationToken A CancellationToken that may be used to cancel the asynchronous iteration.

Returns: IAsyncEnumerator<T> — An enumerator that can be used to iterate asynchronously through the collection.

View source

public StreamIterator<T> GetIterator()

Starts an iterator that cancels the stream when exited early.

Returns: StreamIterator&lt;T&gt;

View source

public ReadableStreamReader<T> GetReader()

Locks the stream.

Returns: ReadableStreamReader&lt;T&gt;

View source

public Task<List<T>> ToArrayAsync()

Reads every value.

Returns: Task<List<T>>

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product