API · Async
asyncFilter()
Await one predicate at a time and keep values whose result is truthy.
Signature
asyncFilter(
fn: (value: T, context: C) => unknown | PromiseLike<unknown>,
): Exstream<T, C> Example
const visible = exstream(documents).asyncFilter((document) => canRead(document.id)) Parameters
fnAwaited for each successful value. Truthy keeps the original value; falsy drops it.
Execution
Concurrency is fixed at 1. Input and output order are preserved, no speculative work is started, and next() is called only after the predicate settles, making the await a backpressure boundary. Use mapAsync() to compute booleans concurrently and a later filter() when higher throughput is required.
Retained values keep their context. A context is materialized only when the callback declares its second parameter.
Errors and cancellation
A throw or rejection becomes a contextual record error with stage asyncFilter; the input is not emitted. Existing record errors pass through. Cancellation prevents new predicates, but running user work must observe context.signal to stop promptly. There are no built-in retry or timeout options.
Forms
stream.asyncFilter(predicate)
exstream.pipeline().asyncFilter(predicate)
exstream.asyncFilter(predicate, stream)
stream.through(exstream.asyncFilter(predicate))