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>
Constructors
Section titled “Constructors”AsyncIterableStream(ReadableStream<T>)
Section titled “AsyncIterableStream(ReadableStream<T>)”public AsyncIterableStream(ReadableStream<T> stream)Creates an iterable view of <code class=“paramref”>stream</code>.
Parameters
| Name | Type | Description |
|---|---|---|
stream |
ReadableStream<T> |
Properties
Section titled “Properties”Locked
Section titled “Locked”public bool Locked { get; }Whether a reader holds the lock.
Value: bool
Stream
Section titled “Stream”public ReadableStream<T> Stream { get; }Underlying stream.
Value: ReadableStream<T>
Methods
Section titled “Methods”CancelAsync()
Section titled “CancelAsync()”public Task CancelAsync()Cancels the stream.
Returns: Task
GetAsyncEnumerator(CancellationToken)
Section titled “GetAsyncEnumerator(CancellationToken)”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.
GetIterator()
Section titled “GetIterator()”public StreamIterator<T> GetIterator()Starts an iterator that cancels the stream when exited early.
Returns: StreamIterator<T>
GetReader()
Section titled “GetReader()”public ReadableStreamReader<T> GetReader()Locks the stream.
Returns: ReadableStreamReader<T>
ToArrayAsync()
Section titled “ToArrayAsync()”public Task<List<T>> ToArrayAsync()Reads every value.
Returns: Task<List<T>>
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product