push-stream-std

@push-stream-std/push-interleave (0.0.6)

Published 2026-07-20 21:37:37 +00:00 by Dvorak

Installation

@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm install @push-stream-std/push-interleave@0.0.6
"@push-stream-std/push-interleave": "0.0.6"

About this package

@push-stream-std/push-interleave

Alternate elements from multiple streams.

Published as @push-stream-std/push-interleave.

Synopsis

import { interleave } from '@push-stream-std/push-interleave';
import { values } from '@push-stream-std/push-pushable';
import { collect } from '@push-stream-std/push-concat';

const a = values([1, 2, 3]);
const b = values(['a', 'b', 'c']);
const c = values([true, false]);

interleave([a, b, c])
  .pipe(collect((err, results) => {
    console.log(results);
    // [1, 'a', true, 2, 'b', false, 3, 'c']
  }));

Install

npm config set @push-stream-std:registry https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm config set -- //hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken "$PACKAGE_TOKEN"
npm install @push-stream-std/push-interleave

Why

Takes multiple push-stream sources and interleaves their output in round-robin order, taking one item from each source per cycle. This is useful for fair scheduling across concurrent data producers, multiplexing multiple input streams into a single output, or load balancing stream processing. Internally buffers items per source using an O(1) amortized head pointer pattern.

API

interleave(sources, options)

Creates a push-stream source that interleaves items from multiple source streams.

Parameters:

  • sources (Array) — An array of push-stream source objects.
  • options.endOnFirst (boolean, default false) — If true, ends the interleaved stream as soon as the first source ends.

Returns: A push-stream source.

Tests

npm test

Tests cover round-robin ordering, handling of sources with different lengths, graceful source completion, and endOnFirst termination.

Requirements

Node.js 22 or later. ESM only.

Keywords

push-stream stream interleave multiplex round-robin
Details
npm
2026-07-20 21:37:37 +00:00
0
SEE LICENSE IN LICENSE
3.9 KiB
Assets (1)
Versions (5) View all
0.0.7 2026-07-21
0.0.6 2026-07-20
0.0.5 2026-07-20
0.0.4 2026-07-19
0.0.3 2026-07-19