Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / merge

Function: merge()

merge<T>(...sources): Stream<T>

Defined in: projects/libraries/streamix/src/lib/streams/merge.ts:33

Merges multiple source streams into a single stream, emitting values as they arrive from any source.

This is useful for combining data from multiple independent sources into a single, unified stream of events. Unlike zip, it does not wait for a value from every stream before emitting; it emits values as they become available.

The merged stream completes only after all source streams have completed. If any source stream errors, the merged stream immediately errors.

Performance characteristics:

  • Synchronous sources with buffered values are drained immediately
  • Asynchronous sources are pulled concurrently

Type Parameters

T

T = any

The type of the values in the streams.

Parameters

sources

...(Stream<T> | Promise<T>)[]

Streams or values (including promises) to merge.

Returns

Stream<T>

A new stream that emits values from all input streams.

Example

typescript
const fast = interval(10);
const slow = interval(100);
const instant = from([1, 2, 3]);

// Values emitted as they arrive
merge(fast, slow, instant).forEach(console.log);

Released under the MIT License.