push-stream-std

@push-stream-std/push-defer (0.0.6)

Published 2026-07-20 21:36:18 +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-defer@0.0.6
"@push-stream-std/push-defer": "0.0.6"

About this package

@push-stream-std/push-defer

Create a placeholder for a push stream that won't start moving until later.

Published as @push-stream-std/push-defer.

Synopsis

import { source } from '@push-stream-std/push-defer';
import { values } from '@push-stream-std/push-pushable';
import { collect } from '@push-stream-std/push-concat';

const deferred = source();
const actual = values([1, 2, 3]);

collect(deferred, (err, result) => {
  console.log(result); // [1, 2, 3]
});

deferred.resolve(actual);

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-defer

Why

Provides deferred placeholder streams for source, through, sink, and duplex types. Operations (writes, pipe, abort) are buffered while the placeholder is unresolved, then replayed to the actual stream once resolve() is called. This enables circular stream graphs, lazy initialization, and streams that depend on result data from later pipeline stages.

API

source()

Returns a deferred source stream placeholder.

  • Returns deferred — Object with pipe, resume, abort, resolve(actualSource) and resolved getter. Buffers pipe until resolved; resolve() triggers the actual source to pipe to the waiting sink.

through()

Returns a deferred through stream placeholder.

  • Returns deferred — Object with write, end, abort, pipe, resume, resolve(actualThrough) and resolved getter. Buffers writes and end calls, replays them on resolve. Also forwards source setter.

sink()

Returns a deferred sink stream placeholder.

  • Returns deferred — Object with write, end, abort, resolve(actualSink) and resolved getter. Buffers writes and end calls, replays them when resolved.

duplex()

Returns a deferred duplex (source + sink) placeholder.

  • Returns deferred — Object with source, sink, pipe, resolve(actualDuplex), abort, and resolved getter. Resolves both source and sink halves from the actual duplex.

Tests

npm test

Tests cover all four stream types, buffered writes/ends, resolve replay, abort propagation, and double-resolve prevention.

Requirements

Node.js 22 or later. ESM only.

Dependencies

Development Dependencies

ID Version
fast-check ^3.23.2

Keywords

push-stream stream defer lazy
Details
npm
2026-07-20 21:36:18 +00:00
0
SEE LICENSE IN LICENSE
4.2 KiB
Assets (1)
Versions (5) View all
0.0.7 2026-07-21
0.0.6 2026-07-20
0.0.5 2026-07-20
0.0.4 2026-07-19
0.0.3 2026-07-19