push-stream-std

@push-stream-std/push-next (0.0.4)

Published 2026-07-19 21:15:42 +00:00 by Dvorak

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.4
"@push-stream-std/push-next": "0.0.4"

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 | undefined or (cb: (err, source?) => void) => void – Called each time the current source ends. When invoked synchronously without arguments, returns the next source or null/undefined to 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, and ended properties.

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

Keywords

push-stream stream next
Details
npm
2026-07-19 21:15:42 +00:00
0
MIT
3.8 KiB
Assets (1)
Versions (7) View all
0.0.9 2026-07-21
0.0.8 2026-07-20
0.0.7 2026-07-20
0.0.6 2026-07-20
0.0.5 2026-07-19