import type { FlowNode } from "../types.js"; import type { Block } from "../declarative.js"; /** One arm of a {@link FlowBuilder.race}: exactly one waited-for event — a * `signal` (a message catch correlated on a process variable) OR a `timer` (a * delay `{ after }` or an instant `{ at }`) — plus the `do` body that runs when * that event wins the race. */ export type RaceArm = ({ signal: { correlationKey: string; }; } | { timer: { after: string; } | { at: string; }; }) & { do: Block; }; /** A compiled race arm: its catch event (a `signal` or `timer` `FlowNode`, reused * from the built-ins) and the body that runs when it wins. */ interface CompiledArm { event: FlowNode; body: FlowNode[]; } declare module "../types.js" { interface FlowNodeRegistry { race: { kind: "race"; arms: CompiledArm[]; }; } } declare module "../declarative.js" { interface FlowBuilder { /** * A first-of event race — a BPMN event-based gateway. Each named arm waits on * exactly one event: a `signal` (a durable message catch correlated on a * process variable) or a `timer` (`{ after }` a delay, or `{ at }` an * instant). The engine arms every catch at once; the FIRST to fire wins, its * arm's `do` body runs, and the losing catch events are cancelled. Every arm's * body converges on whatever follows the race. * * ```ts * w.race({ * "review-ready": { signal: { correlationKey: "prKey" }, do: (b) => b.run("re-review", reReview) }, * "review-timeout": { timer: { after: "=reviewWaitTimeout" }, do: (b) => b.run("escalate", escalate) }, * }); * ``` */ race(arms: Record): FlowBuilder; } } export {};