@push-stream-std/push-exhaust-map (0.0.3)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-exhaust-map@0.0.3"@push-stream-std/push-exhaust-map": "0.0.3"About this package
push-exhaust-map
Ignore new values while inner stream is active.
Published as @push-stream-std/push-exhaust-map.
Synopsis
import { exhaustMap } from '@push-stream-std/push-exhaust-map';
import { values } from '@push-stream-std/push-values';
import { collect } from '@push-stream-std/push-collect';
const source = values([1, 2, 3]);
const mapped = exhaustMap((n) => {
return values([n * 10, n * 100]);
});
collect(source.pipe(mapped), (err, result) => {
console.log(result); // [10, 100] — 2 and 3 are dropped while inner is active
});
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-exhaust-map
Description
A through stream that maps each value to an inner stream, then ignores (drops) incoming values while the inner stream is active. Once the inner stream ends, the next pending value triggers a new inner stream. This prevents overlapping operations — useful for save-on-submit buttons, guaranteed single-flight requests, or any scenario where concurrent inner streams should be avoided.
API
exhaustMap(mapper)
Returns a through stream that maps values to inner streams, dropping incoming values while an inner stream is active.
- mapper
(value) => result— A function called with each accepted value. Can return:- A push-stream source (piped as inner stream)
- An array (items written downstream immediately)
- Any other value (written downstream as a single value)
- Returns
through— A push-stream through. Values arriving while an inner stream is active are buffered; only the most recent pending value is used when the inner stream completes. Earlier pending values are dropped.
Tests
npm test
Tests cover inner stream mapping, value drop while inner active, array mapper results, scalar mapper results, and abort/end propagation.
Requirements
Node.js 18 or later. ESM only.
License
MIT