@epikodelabs/streamix / src/public-api / gate
Function: gate()
gate<
T>(control,options?):Operator<T,T>
Defined in: projects/libraries/streamix/src/lib/operators/gate.ts:66
Starts and stops delivery without unsubscribing from the source.
A boolean control stream opens the gate with true and closes it with false; the gate starts closed. While open, source values pass through immediately. While closed, GateOptions decides whether values are dropped, kept as the latest, or buffered up to a capacity. The source keeps running either way — this is delivery control, not backpressure.
Opening the gate flushes retained values in arrival order before later values pass through. Buffered values are discarded if the source completes while the gate is closed. The control stream may end independently: the gate keeps its last state, and the output completes when the source ends.
Errors from either stream fail the output. A buffer capacity that is not a positive integer fails synchronously when the operator is created.
Typical scenarios:
- Pausing UI or log delivery while a panel is hidden, then resuming without reconnecting the source.
- Keeping only the newest value while paused (
closed: 'latest'). - Buffering a bounded backlog while paused and replaying it in order (
closed: 'buffer').
This is not backpressure: the source is still pulled. Use buffer or throttle for rate or volume control.
Type Parameters
T
T = any
The type of values flowing through the gate.
Parameters
control
PipeInput<boolean>
Boolean stream that opens (true) or closes (false) the gate.
options?
GateOptions = {}
Behavior while closed; defaults to dropping values.
Returns
Operator<T, T>
An operator that forwards source values according to the control.
Example
// `source` is the value stream; `paused` emits the boolean control.
// Keep at most 100 values while paused, then release them in order.
const gated = pipe(source, gate(paused, {
closed: 'buffer',
capacity: 100,
overflow: 'drop-oldest',
}));