Files
push-take-until/README.md
T

55 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

# @push-stream-std/push-take-until
2026-07-19 13:44:10 -07:00
Take values from a source stream until a signal stream emits or ends.
Published as `@push-stream-std/push-take-until`.
## Synopsis
```js
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
```bash
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
```
## Why
2026-07-19 13:44:10 -07:00
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
```bash
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 22 or later. ESM only.
2026-07-19 13:44:10 -07:00