@push-stream-std/push-notify (0.0.6)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-notify@0.0.6"@push-stream-std/push-notify": "0.0.6"About this package
push-notify
Observable-like source that broadcasts values to multiple listeners.
Published as @push-stream-std/push-notify.
Synopsis
import notify from '@push-stream-std/push-notify';
import concat from '@push-stream-std/push-concat';
const notifier = notify();
notifier.listen().pipe(concat((err, result) => {
console.log('listener 1:', result); // [1, 2]
}));
notifier.listen().pipe(concat((err, result) => {
console.log('listener 2:', result); // [1, 2]
}));
notifier(1);
notifier(2);
notifier.end();
Direct piping:
const sink = concat((err, result) => console.log(result));
notifier.pipe(sink);
notifier(42);
notifier.end();
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-notify
Description
A broadcast source that emits values to all piped listeners. Each call to notify.listen() returns a new source stream that receives future values — new listeners do not receive past values. Backpressure is respected: if any listener is paused, all listeners buffer until the paused listener resumes. Calling notifier.end(err) terminates all listeners.
API
notify()
Creates a notifier.
- Returns A function
notifier(value)that also has.listen(),.end(), and.pipe()methods.
notifier(value)
Push a value to all piped listeners.
- Returns
trueif all listeners accepted the value without buffering,falseif buffering occurred.
notifier.listen()
Create a new listener source.
- Returns A source stream that receives future broadcasts. Can be piped to sinks.
notifier.end(err?)
End all listeners.
notifier.pipe(sink)
Create a listener and pipe it directly to a sink.
Tests
npm test
Tests cover broadcasting to multiple listeners, listener creation/removal, end propagation, backpressure buffering, and aborted listeners.
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.23.2 |