@push-stream-std/push-with-latest-from (0.0.5)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-with-latest-from@0.0.5"@push-stream-std/push-with-latest-from": "0.0.5"About this package
push-with-latest-from
Combine a primary source with the latest values from auxiliary sources.
Published as @push-stream-std/push-with-latest-from.
Synopsis
import withLatestFrom from '@push-stream-std/push-with-latest-from';
import pushable from '@push-stream-std/push-pushable';
const primary = pushable();
const aux = pushable();
const combined = withLatestFrom(aux);
const sink = {
paused: false,
write(v) { console.log('tuple:', v); },
end() { console.log('done'); }
};
primary.pipe(combined).pipe(sink);
aux.push('latest from aux');
primary.push(1);
// Output: tuple: [1, 'latest from aux']
primary.push(2);
// Output: tuple: [2, 'latest from aux']
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-with-latest-from
Description
A through stream that subscribes to one or more auxiliary sources. When the primary source emits a value, it is combined with the latest value from each auxiliary source into an array [primaryValue, ...auxValues]. Emissions are suppressed until every auxiliary source has produced at least one value. Auxiliary sources are wired up during pipe(), proxied so their values are captured without flowing through the main sink until the primary fires.
API
withLatestFrom(...sources)
Creates a with-latest-from through stream.
- sources
...PushStreamSource– One or more auxiliary push-stream sources. Values from these are cached. - Returns A through stream with
pipe(),write(),end(),abort(),resume(),paused, andended. Piped sink receives[primaryValue, ...latestAuxValues]arrays.
Tests
npm test
Tests cover tuple emission with latest aux values, suppressed emission before aux sources have data, multiple aux sources, and abort propagation to proxied sources.
Requirements
Node.js 18 or later. ESM only.
License
MIT