Files
push-take-until/README.md
T
Tenere CI 10f2d98ada
CI / test (18) (push) Waiting to run
CI / test (20) (push) Waiting to run
CI / test (22) (push) Waiting to run
initial import
2026-07-19 13:44:10 -07:00

1.8 KiB
Raw Permalink Blame History

push-take-until

Take values from a source stream until a signal stream emits or ends.

Published as @push-stream-std/push-take-until.

Synopsis

import takeUntil from '@push-stream-std/push-take-until';

const signal = pushable();
const untilSignal = takeUntil(signal);

values([1, 2, 3, 4, 5]).pipe(untilSignal).pipe(collect(function (err, result) {
  console.log(result); // [1, 2] — signal ended after 2 values
}));

// End the signal stream to stop the outer stream
signal.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-take-until

Description

A push-stream through that passes through values from the source until the provided signal stream ends. When the signal stream ends (either normally or via abort), the take-until stream immediately ends the upstream source and downstream sink, closing the pipeline. This is useful for implementing cancellation patterns — for example, taking values from an event stream until a "stop" button is clicked.

API

takeUntil(signalStream)

Creates a take-until through stream.

  • signalStream object A push-stream source. The take-until stream pipes the signal stream to an internal sink that tracks when the signal ends. When the signal's end() or abort() fires, the take-until stream ends.
  • Returns A through object with pipe(), write(), end(), abort(), resume(), source, paused, ended.

Tests

npm test

Tests cover passthrough before signal ends, stopping after signal end, normal end without signal, signal abort propagation, and idempotent signal end handling.

Requirements

Node.js 18 or later. ESM only.

License

MIT