@push-stream-std/push-merge-map (0.0.8)
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, ornull/undefinedto skip the item.options.concurrency(number, defaultInfinity) — 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.