Skip to content

@oona/vlo / index / fanOutRuns

Function: fanOutRuns() ​

fanOutRuns<I>(target, select, options): SeqStep

Defined in: sdk/ts/sdk/src/core/helpers/sequence.ts:157

A sequence phase that spawns one child run of target per item select returns, at most concurrency at a time, with step ids ${workflow}#${index}.

select has the same purity rule as fanOut. Each item is the child's start input. The phase stores a ChildResult per item in results[workflow], in item order; read it with fanOutRunsResultsOf. An empty selection stores [] and moves on. A child that did not complete fails the run, unless onFailure: "continue" records its status and moves on. The child workflow must be registered on the same host.

Throws a TypeError synchronously unless concurrency is an integer ≥ 1.

Type Parameters ​

I ​

I extends Json = Json

Parameters ​

target ​

string | { name: string; }

select ​

(state) => I[]

options ​

FanOutRunsOptions

Returns ​

SeqStep

Example ​

ts
import { defineWorkflow, fanOutRuns, fanOutRunsResultsOf, resultOf, sequence, step } from "@oona/vlo";
import { plan, summarise } from "./activities.ts";
import { readSource } from "./read-source.workflow.ts";

export default defineWorkflow("research", sequence([
  step(plan),
  fanOutRuns(readSource, (s) => resultOf(s, plan).sourceIds.map((sourceId) => ({ sourceId })), {
    concurrency: 5,
    onFailure: "continue",
  }),
  step(summarise, (s) => ({ read: fanOutRunsResultsOf(s, readSource).filter((r) => r.status === "succeeded").length })),
]));