🌊 Joins streams end to end, reading each one only once the previous has closed.

Info

The result pulls lazily — a later stream is not touched until the reader has drained everything before it, so an endless source can sit at the end without being buffered.

Syntax

TypeScript
import { concatStreams } from '@opentf/std';

concatStreams<T>(...streams: ReadableStream<T>[]): ReadableStream<T>;

Parameters

NameTypeDescription
streamsReadableStream<T>[]The streams to concatenate.

Returns

A stream over every chunk, in stream order.

Cancelling the result cancels the stream in flight and every stream still queued. Use mergeStreams when you want chunks as soon as any source produces them.

Examples

TypeScript
const all = concatStreams(header, body, footer);
await streamToText(all) //=> 'headerbodyfooter'

Order holds even when an earlier source is slower:

TypeScript
// `slow` finishes first in the output despite taking longer per chunk.
await streamToArray(concatStreams(slow, fast)) //=> ['a', 'b', 'c', 'd']
Last updated on
Edit this page