Skip to content

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

View source

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>

View source

public bool Locked { get; }

Whether a reader currently holds the lock.

Value: bool

View source

public Task CancelAsync()

Cancels the stream. Throws when a reader holds the lock.

Returns: Task

View source

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>

View source

public ReadableStreamReader<T> GetReader()

Locks the stream and returns its reader.

Returns: ReadableStreamReader&lt;T&gt;

View source

public Task<List<T>> ToArrayAsync()

Reads every chunk into a list.

Returns: Task<List<T>>

View source

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