@push-stream-std/push-throttle (0.0.6)
Published 2026-07-20 19:00:59 +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-throttle@0.0.6"@push-stream-std/push-throttle": "0.0.6"About this package
push-throttle
Throttle stream to max rate with leading/trailing edge control.
Published as @push-stream-std/push-throttle.
Synopsis
import throttle from '@push-stream-std/push-throttle';
import pushable from '@push-stream-std/push-pushable';
const source = pushable();
const sink = {
paused: false,
write(v) { console.log(v); },
end() { console.log('done'); }
};
source.pipe(throttle(1000, { leading: true, trailing: true })).pipe(sink);
source.push(1); // emitted immediately (leading)
source.push(2); // queued, emitted after 1s (trailing)
source.push(3); // replaces queued value
source.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-throttle
Description
A through stream that limits the rate at which values pass through. Supports leading edge (emit first value immediately) and trailing edge (emit most recent value after interval elapses) strategies. Intermediate values received during the cooldown period replace the pending value, so only the most recent value is emitted on the trailing edge when both options are enabled.
API
throttle(interval, options)
Creates a throttling through stream.
- interval
number– Minimum time in milliseconds between emissions. - options
object(optional):- leading
boolean(defaulttrue) – Emit the first value immediately when no cooldown is active. - trailing
boolean(defaultfalse) – Emit the most recent pending value after the interval elapses.
- leading
- Returns A through stream with
pipe(),write(),end(),abort(),resume(),paused, andended.
Tests
npm test
Tests cover leading edge immediate emission, trailing edge deferred emission, value replacement for pending values, interval enforcement, end/flush of trailing values, and abort cleanup.
Requirements
Node.js 18 or later. ESM only.
License
MIT
Keywords
push-stream
stream
throttle