Skip to content

TS SDK: add multi-way branching with dag.switch - #73444

Closed
jason810496 wants to merge 5 commits into
apache:mainfrom
jason810496:feature/ts-sdk/multi-way-branching
Closed

jason810496 wants to merge 5 commits into
apache:mainfrom
jason810496:feature/ts-sdk/multi-way-branching

Conversation

@jason810496

@jason810496 jason810496 commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

TS SDK: add multi-way branching with dag.switch

Why

The multi-way form of the same ADR: TypeScript's switch/case.

How

const decider = dag.task("pick_path", async ({ rows }: { rows: number }) =>
  rows > 1000 ? handleLong : handleShort,
);
const picked = decider({ rows: extracted });

dag.switch(picked).case(handleLong).case(handleShort);
  • Both the decider and each case are task references the Dag already handed back, per decision 2, so the compiler checks the candidate exists and renaming a handler cannot silently rewire a Dag.
  • The task's value on the wire is the chosen task's id, which is what a downstream task reads back from its XCom.
  • No default case, per decision 3: a decider returning anything outside its cases fails the task, naming what it chose and what it could have chosen. A branch with no case at all decides nothing and is rejected when the Dag is read.
  • Exactly one case is selected — the limitation that ADR records for every language SDK.
  • As with dag.if, the decider is serialized with _can_skip_downstream and writes the skipmixin_key XCom, so a cleared case stays skipped.

What

  • dag.switch and the chainable Branch. Unlike a condition's then, case is not a thenable trap, so nothing needs guarding here.

Was generative AI tooling used to co-author this PR?

@jason810496
jason810496 force-pushed the feature/ts-sdk/multi-way-branching branch from b9993a3 to e6303cb Compare September 30, 2026 05:12
@jason810496

Copy link
Copy Markdown
Member Author

Finished in #74070.

@jason810496 jason810496 closed this Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants