ReadableStream<T>
Namespace: Vercel.AI.Util
public class ReadableStream<T>Pull-based readable stream. Supports enqueue, close, error, backpressure via pull, and a single reader.
Type parameters
| Name | Description |
|---|---|
T |
Inheritance: object
Constructors
Section titled “Constructors”ReadableStream(Action<ReadableStreamController<T>>?, Func<ReadableStreamController<T>, Task>?, Func<Task>?)
Section titled “ReadableStream(Action<ReadableStreamController<T>>?, Func<ReadableStreamController<T>, Task>?, Func<Task>?)”public ReadableStream(Action<ReadableStreamController<T>>? start = null, Func<ReadableStreamController<T>, Task>? pull = null, Func<Task>? cancel = null)Creates a stream. <code class=“paramref”>start</code> runs before the constructor returns.
Parameters
| Name | Type | Description |
|---|---|---|
start |
Action<ReadableStreamController<T>> | |
pull |
Func<ReadableStreamController<T>, Task> | |
cancel |
Func<Task> |
Properties
Section titled “Properties”Locked
Section titled “Locked”public bool Locked { get; }Whether a reader currently holds the lock.
Value: bool
Methods
Section titled “Methods”CancelAsync()
Section titled “CancelAsync()”public Task CancelAsync()Cancels the stream. Throws when a reader holds the lock.
Returns: Task
FromArray(IReadOnlyList<T>?)
Section titled “FromArray(IReadOnlyList<T>?)”public static ReadableStream<T> FromArray(IReadOnlyList<T>? values)A stream that emits <code class=“paramref”>values</code> and then closes.
Parameters
| Name | Type | Description |
|---|---|---|
values |
IReadOnlyList<T> |
Returns: ReadableStream<T>
GetReader()
Section titled “GetReader()”public ReadableStreamReader<T> GetReader()Locks the stream and returns its reader.
Returns: ReadableStreamReader<T>
ToArrayAsync()
Section titled “ToArrayAsync()”public Task<List<T>> ToArrayAsync()Reads every chunk into a list.
Returns: Task<List<T>>
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product