@push-stream-std/push-timeout (0.0.3)
Published 2026-07-19 21:14:28 +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-timeout@0.0.3"@push-stream-std/push-timeout": "0.0.3"About this package
push-timeout
Error if no value arrives within a time window, with optional fallback.
Published as @push-stream-std/push-timeout.
Synopsis
import timeout from '@push-stream-std/push-timeout';
import pushable from '@push-stream-std/push-pushable';
const source = pushable();
const sink = {
paused: false,
write(v) { console.log(v); },
end(err) { if (err) console.error('timeout:', err.message); }
};
source.pipe(timeout(5000)).pipe(sink);
source.push(1); // resets timer
// if no value for 5s, sink.end() called with timeout error
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-timeout
Description
A through stream that monitors the time between consecutive values. If no value arrives within the configured ms window, the stream either errors (default) or falls back to a value produced by the onTimeout callback and ends gracefully. Supports timer injection via timer/clearTimer options for testability and CI compatibility.
API
timeout(ms, options)
Creates a timeout through stream.
- ms
number– Timeout window in milliseconds. - options
object(optional):- onTimeout
() => value(optional) – If provided, called when timeout fires. The return value (if notundefined) is written to the sink before ending. If omitted, an error is raised. - timer
Function(defaultsetTimeout) – Timer function, useful for test injection. - clearTimer
Function(defaultclearTimeout) – Timer cleanup function.
- onTimeout
- Returns A through stream with
pipe(),write(),end(),abort(),resume(),paused, andended.
Tests
npm test
Tests cover timeout error emission, timer reset on each value, onTimeout fallback value, abort cleanup of pending timers, and end propagation.
Requirements
Node.js 18 or later. ESM only.
License
MIT
Keywords
push-stream
stream
timeout