API · Async

resolve()

Await promise values already present in the stream, with bounded parallelism and optional completion-order output.

Signature

resolve(
  parallelism?: number,
  preserveOrder?: boolean,
): Exstream<ResolvedValue<T>, C>

Example

const responses = exstream(urls)
  .map((url) => fetch(url))
  .resolve(8, false)

Parameters

parallelism

Type positive integer | InfinityDefault 1

Maximum number of promises observed at once. Positive integers and Infinity are accepted; zero, negatives, fractions, and non-numeric values are rejected. The JavaScript runtime applies Number(), so any value coercing to an allowed number is accepted; TypeScript accepts numbers only.

preserveOrder

Type booleanDefault true

When true, output follows input order. When false, fulfilled values are emitted in completion order. Ordered mode may retain later completed values behind an earlier pending promise. The runtime uses truthiness; the public TypeScript API accepts booleans only.

Behavior

Every successful input must be a native Promise recognized by the active JavaScript realm. Although the TypeScript utility type is expressed in terms of PromiseLike, the current runtime check uses instanceof Promise; a plain thenable is therefore rejected as a non-promise. That rejection becomes a record error rather than passing through. At most parallelism promises are active, and downstream backpressure limits further upstream demand.

resolve() is useful when promises were created elsewhere or when a previous synchronous operator intentionally emits promises. Prefer mapAsync() when Exstream should own callback execution, retry, timeout, or cancellation policy.

parallelism limits how many promise records Exstream observes concurrently. It cannot stop promises that were created eagerly before entering the stream from already running. To bound operation creation, create promises lazily in an upstream map() under resolve() demand, or use mapAsync().

Errors

A rejected promise becomes a contextual record error associated with the original promise input. Handle it downstream to continue processing. A fatal rejection or graph failure aborts the operator.

Fulfilled values and rejected errors retain the input promise’s record context. Ordered mode keeps that association while buffering out-of-order settlements.

Cancellation

Destroying or aborting the branch stops scheduling new promises and discards later results. It cannot cancel a bare promise by itself; cancellation must be wired into the operation that created that promise.

Forms

resolve() is available on streams and reusable pipelines. Its direct standalone form takes both configuration arguments before the stream; its curried form may omit them:

stream.resolve(8, false)
exstream.pipeline().resolve(8, false)
exstream.resolve(8, false, stream)
stream.through(exstream.resolve(8, false))

mapAsync(), map(), merge()