push-stream-std

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

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

About this package

push-sample

Sample a push-stream at regular intervals or on an external signal.

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

Synopsis

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

const sampler = sample(100); // sample every 100ms

values([1, 2, 3, 4, 5]).pipe(sampler);

sampler.pipe(collect((err, results) => {
  console.log(results); // latest value at each 100ms interval
}));

With a signal source:

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

const clock = values([null, null, null]); // trigger 3 samples
const sampler = sample({ signal: clock });

values([10, 20, 30, 40, 50]).pipe(sampler).pipe(collect((err, results) => {
  console.log(results); // [10, 20, 30] — one per signal end event
}));

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

Description

A push-stream through operator that periodically emits the most recently received value. It can be driven by a time interval (using setInterval) or by an external signal stream. When driven by a signal, each time the signal source ends (end-of-signal event), the latest buffered value is emitted. The operator stores only the latest value; intermediate values between sample ticks are overwritten.

API

sample(options)

  • options — Either a number (interval in milliseconds) or an object:
    • options.interval (number, default 1000) — Sample interval in milliseconds. Ignored if signal is provided. Set to 0 to never auto-sample.
    • options.signal (push-stream source, optional) — A source stream whose end events trigger samples. The signal stream is piped internally; each time its proxy end handler fires, the latest value is emitted.

Returns a push-stream through. Writes update the buffered latest value; the value is emitted on each timer tick or signal tick. Only values received since the last sample are emitted (hasValue resets after each sample).

Tests

npm test

Tests cover interval-driven sampling, signal-driven sampling, emitting only the latest value between samples, and ending the stream.

Requirements

Node.js 18 or later. ESM only.

License

MIT

Keywords

push-stream sample interval signal
Details
npm
2026-07-19 23:32:03 +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