gossamer/stream/readable_stream/reader

The pull-side cursor over a ReadableStream. Acquire one with gossamer/stream/readable_stream.get_reader then call read to pull chunks. Release the lock via release_lock when done.

Types

A JavaScript ReadableStreamDefaultReader — a locked reader over a ReadableStream.

See ReadableStreamDefaultReader on MDN.

pub type Reader(a)

Values

pub fn cancel(
  reader: Reader(a),
  reason reason: r,
) -> promise.Promise(Result(Nil, stream.StreamLifecycleError))

Cancels the stream and releases the reader’s lock. Returns Errored if the underlying source’s cancel callback throws or rejects.

pub fn closed(
  reader: Reader(a),
) -> promise.Promise(Result(Nil, stream.StreamLifecycleError))

Resolves when the stream closes. Returns Errored if the stream enters an errored state; the reason is the variant’s payload.

pub fn read(
  reader: Reader(a),
) -> promise.Promise(
  Result(option.Option(a), stream.StreamLifecycleError),
)

Reads the next chunk: Some(chunk) while data remains, None once the stream is exhausted. Returns Errored if the stream enters an errored state, or if the reader no longer holds the lock; the reason payload distinguishes the two.

pub fn release_lock(reader: Reader(a)) -> Nil

Releases the reader’s lock on the stream. Pending reads reject asynchronously after release.

Search Document