executeInParallel handles this: run multiple steps concurrently with optional rate limiting, and get all results back in order.
Basic Usage
Wrap each job in an arrow function and pass them as an array. Results come back in the same order you submitted them, with each result telling you whether the job succeeded or failed:workflow.ts
Parameters
| Parameter | Type | Description |
|---|---|---|
jobs | Array<() => Promise<T> | T> | Array of functions that return a step, evaluator, or child workflow call (or any value). Do not pass promises directly. |
concurrency | number | Maximum number of jobs running at once. Default: Infinity (no limit). |
onJobCompleted | (result: ParallelJobResult<T>) => void | Optional callback invoked as each job completes, in completion order (not submission order). |
Result Type
The function returnsPromise<Array<ParallelJobResult<T>>>, sorted by original job index (so results stay in the same order you submitted them).
Each element is a discriminated union:
| When | Shape | Fields |
|---|---|---|
| Success | { ok: true; result: T; index: number } | result is the job’s return value |
| Failure | { ok: false; error: unknown; index: number } | error is the thrown value |
Concurrency Limit
When you’re calling an external API that has rate limits, useconcurrency to cap how many jobs run at once:
concurrency: 3, at most three enrichment calls run at a time. When one finishes, the next starts.
onJobCompleted Callback
onJobCompleted fires once per job in completion order (fastest first), not submission order. Use it for logging progress or streaming partial results:
Examples
Batch enrichment with rate limiting
Enrich a list of leads, capping concurrency to respect API rate limits:workflow.ts
Gather data from multiple sources
Run different steps in one batch — results stay in job order:Child workflows in parallel
Run multiple child workflows with a concurrency cap:Important: Wrap in arrow functions
Jobs must be functions that return the step, evaluator, or child workflow call. Do not pass promises:executeInParallel control when each job runs and respect the concurrency limit.