@push-stream-std/push-combine-latest (0.0.4)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-combine-latest@0.0.4"@push-stream-std/push-combine-latest": "0.0.4"About this package
push-combine-latest
Combine multiple sources, emitting on any update.
Published as @push-stream-std/push-combine-latest.
Synopsis
import combineLatest from '@push-stream-std/push-combine-latest';
const sourceA = /* push stream producing 'a', 'b' */;
const sourceB = /* push stream producing 1, 2 */;
const combined = combineLatest([sourceA, sourceB]);
combined.pipe(sink);
// Output: ['b', 1], ['b', 2]
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-combine-latest
Description
A source-like stream that subscribes to multiple upstream push-stream sources and emits an array of the latest value from each source whenever any source emits a new value. Emits are only produced when all sources have delivered at least one value. Incomplete sources (that ended without producing a value) prevent any emission. Useful for reactive computations where you need the most recent state from several data streams.
API
combineLatest(sources)
Creates a combine-latest stream.
- sources
Array– An array of push-stream source objects. - Returns A stream with
pipe(),write(),end(),abort(),resume(),paused, andended. The stream acts as a sink for individual sources and as a source for the downstream.
Tests
npm test
Tests cover emitting combined values when all sources have data, sources emitting at different rates, a single source wrapping values in arrays, both sources empty (no emission), one empty and one non-empty source (no emission due to incomplete source), abort propagation, and three-source combination.
Requirements
Node.js 18 or later. ESM only.
License
MIT