@push-stream-std/push-next (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-next@0.0.5"@push-stream-std/push-next": "0.0.5"About this package
push-next
Lazily get the next source when the current source ends.
Published as @push-stream-std/push-next.
Synopsis
import { next } from '@push-stream-std/push-next';
import pushable from '@push-stream-std/push-pushable';
import concat from '@push-stream-std/push-concat';
const values = pushable();
const source = next(function getNextSource() {
values.push(1);
values.push(2);
values.end();
return null;
});
source.pipe(concat((err, result) => {
if (err) return console.error(err);
console.log(result); // [1, 2]
}));
source.resume();
With async callback support:
const source = next(function getNextSource(cb) {
fetchData((err, data) => {
if (err) return cb(err);
const src = pushable();
src.push(data);
src.end();
cb(null, src);
});
});
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-next
Description
A source stream that lazily fetches the next source whenever the current one ends. When a source ends, getNextSource is called to provide the next source. If it returns a stream, that stream becomes the new data source. If it returns null or undefined, the overall stream ends. Supports both synchronous return and callback-based async (getNextSource(cb)) via function-length detection.
API
next(getNextSource)
Creates a lazy source stream.
- getNextSource
() => source | null | undefinedor(cb: (err, source?) => void) => void– Called each time the current source ends. When invoked synchronously without arguments, returns the next source ornull/undefinedto end. When invoked with one argument (detected via.length === 1), calls the callback with(err, source). - Returns A source stream with
pipe(),resume(),abort(err),sink,paused, andendedproperties.
Tests
npm test
Tests cover syncing multiple sources sequentially, async source fetching, error propagation via callback, ending when getNextSource returns null, and aborting mid-stream.
Requirements
Node.js 18 or later. ESM only.
License
MIT
Dependencies
Dependencies
| ID | Version |
|---|---|
| @push-stream-std/push-stream-base | * |
Development Dependencies
| ID | Version |
|---|---|
| fast-check | ^3.0.0 |