push-stream-std

@push-stream-std/push-merge-map (0.0.8)

Published 2026-07-20 21:37:59 +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-merge-map@0.0.8
"@push-stream-std/push-merge-map": "0.0.8"

About this package

@push-stream-std/push-merge-map

Map to inner sources, merge with concurrency.

Published as @push-stream-std/push-merge-map.

Synopsis

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

// For each input item, create a stream and merge outputs
values([1, 2, 3])
  .pipe(mergeMap((x) => {
    const s = values([x * 10, x * 10 + 1]);
    return s;
  }, { concurrency: 2 }))
  .pipe(collect((err, results) => {
    console.log(results); // [10, 11, 20, 21, 30, 31]
  }));

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-merge-map

Why

A push-stream through operator that maps each input item to an inner push-stream source using a mapper function, then merges the outputs from all active inner sources downstream. This enables fan-out/fan-in patterns where each input item triggers a sub-stream. Concurrency control limits how many inner streams can be active at once — excess items are queued pending.

API

mergeMap(mapper, options)

Creates a through stream that maps items to inner sources and merges their outputs.

Parameters:

  • mapper (function) — Called with each input data item. Must return a push-stream source, or null/undefined to skip the item.
  • options.concurrency (number, default Infinity) — Maximum number of inner sources allowed to run simultaneously. Items beyond this limit are queued.

Returns: A push-stream through.

Tests

npm test

Tests cover basic mapping and merging, concurrency enforcement, mapper error handling, null/falsy return from mapper (skip), inner stream error propagation, and end-on-all-complete behavior.

Requirements

Node.js 22 or later. ESM only.

Keywords

push-stream merge-map merge flatten concurrency
Details
npm
2026-07-20 21:37:59 +00:00
0
SEE LICENSE IN LICENSE
4.2 KiB
Assets (1)
Versions (6) View all
0.0.9 2026-07-21
0.0.8 2026-07-20
0.0.7 2026-07-20
0.0.6 2026-07-19
0.0.5 2026-07-19