push-stream-std

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

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

About this package

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

Why

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 not undefined) is written to the sink before ending. If omitted, an error is raised.
    • timer Function (default setTimeout) – Timer function, useful for test injection.
    • clearTimer Function (default clearTimeout) – Timer cleanup function.
  • Returns A through stream with pipe(), write(), end(), abort(), resume(), paused, and ended.

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

Keywords

push-stream stream timeout
Details
npm
2026-07-21 15:53:43 +00:00
0
SEE LICENSE IN LICENSE
latest
3.4 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