Skip to main content

Function: parallelMerge()

parallelMerge<TOutput>(fanOut, branches, merge, processorNames?, failureMode?): Processable<unknown, TOutput>

Defined in: packages/core/src/graph/parallel-merge.ts:81

Fan one input out to several branches and merge what comes back.

The graph is built once, when the processor is created: a fan-out step, one step per branch reading its slot, and a merge step joining the source, the fan-out and every branch. A fan-out returning an array (or { inputs }) gives branch i element i; any other value goes to every branch.

Failure modes​

  • 'fail-fast' (default): the first branch failure fails the whole call — but rejection is reported only after every sibling has settled, and siblings are not cancelled. This keeps the hook contract honest (no branch reports success after the composite reported failure), at a cost: time-to-rejection is the slowest sibling, not the first failure. A sibling that hangs holds the rejection open with it. Branches doing long-running work should carry their own timeouts (e.g. an AbortSignal / model-call timeout) — this pattern does not impose one.
  • 'settle': every branch runs to completion; failures are handed to the merge step as errors instead of failing the call.

Type Parameters​

TOutput​

TOutput = unknown

Parameters​

fanOut​

Processable

branches​

Processable<unknown, unknown>[]

merge​

Processable

processorNames?​

string[]

failureMode?​

"fail-fast" | "settle"

Returns​

Processable<unknown, TOutput>

Example​

const parallel = parallelMerge(
splitterBot, // Fan-out: prepares inputs
[bot1, bot2, bot3], // Parallel: run concurrently
mergerBot // Fan-in: combines results
);

const result = await parallel.process(input);