push-stream-std

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

Published 2026-07-19 23:32:05 +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-share@0.0.6
"@push-stream-std/push-share": "0.0.6"

About this package

push-share

Share a single push-stream source subscription among multiple sinks.

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

Synopsis

import { share } from '@push-stream-std/push-share';
import { values } from '@push-stream-std/push-values';
import { collect } from '@push-stream-std/push-collect';

const source = values([1, 2, 3]);
const shared = share(source);

collect({ stream: shared, result: false }, (err, results) => {
  console.log('sink 1:', results); // [1, 2, 3]
});

collect({ stream: shared, result: false }, (err, results) => {
  console.log('sink 2:', results); // [1, 2, 3]
});

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

Description

A push-stream multicasting operator that takes a single source stream and fans out its values to multiple sinks. The underlying source is subscribed only once, avoiding duplicate work or side effects. Values are broadcast to all connected sinks. Sinks can be dynamically added and removed via pipe() and unpipe(). When all sinks are unsubscribed, the source subscription is ended. Each sink receives the same sequence of values from the shared source.

API

share(source)

  • source — A push-stream source object (with pipe, optionally resume).

Returns a push-stream through with pipe(), unpipe(), end(), abort(), and resume().

stream.pipe(sink)

Adds a sink to the shared subscription. If this is the first sink, the source is subscribed. Returns the sink.

stream.unpipe(sink)

Removes a sink from the shared subscription. When all sinks are removed, the source is ended.

Tests

npm test

Tests cover multiple sinks receiving all values, dynamic sink addition, sink removal with unpiped, source auto-subscription on first pipe, and source auto-end when all sinks disconnect.

Requirements

Node.js 18 or later. ESM only.

License

MIT

Keywords

push-stream share multicast pub/sub
Details
npm
2026-07-19 23:32:05 +00:00
0
MIT
3.4 KiB
Assets (1)
Versions (6) 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-19
0.0.5 2026-07-19