Skip to content

Function: concat()

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

Defined in: streams/concat.ts:19

Creates a stream that subscribes to multiple streams in sequence.

This operator will subscribe to the first stream and yield all of its values. Once the first stream completes, it will then subscribe to the second stream, and so on, until all streams have completed. The resulting stream will complete only after the last source stream has completed.

If any of the source streams errors, the concatenated stream will also error and stop processing the remaining streams.

Type Parameters

T

T = any

The type of the values in the streams.

Parameters

sources

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

An array of streams to concatenate.

Returns

Stream<T>

A new stream that emits values from all input streams in sequence.

Examples

From concat.spec.ts:5

typescript
const source1 = from(['source1_value1', 'source1_value2']);
const source2 = from(['source2_value1', 'source2_value2']);
const concatStream = concat(source1, source2);
const emittedValues: any[] = [];
const subscription = concatStream.subscribe({
  next: (value: any) => emittedValues.push(value),
  complete: () => {
    expect(emittedValues).toEqual([
      'source1_value1',
      'source1_value2',
      'source2_value1',
      'source2_value2',
    ]);

    subscription.unsubscribe();
    done();
  },
});

Released under the MIT License.