push-stream-std

@push-stream-std/push-throttle (0.0.9)

Published 2026-07-21 15:53:31 +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.9
"@push-stream-std/push-throttle": "0.0.9"

About this package

@push-stream-std/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

Why

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 (default true) – Emit the first value immediately when no cooldown is active.
    • trailing boolean (default false) – Emit the most recent pending value after the interval elapses.
  • Returns A through stream with pipe(), write(), end(), abort(), resume(), paused, and ended.

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 22 or later. ESM only.

Keywords

push-stream stream throttle
Details
npm
2026-07-21 15:53:31 +00:00
0
SEE LICENSE IN LICENSE
latest
3.6 KiB
Assets (1)
Versions (6) View all
0.0.9 2026-07-21
0.0.8 2026-07-21
0.0.7 2026-07-20
0.0.6 2026-07-20
0.0.5 2026-07-19