Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/api-reference/task-generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ _System Task_ - Executes multiple task branches in parallel and waits for all to
```typescript
import { forkTask, forkTaskJoin } from "@io-orkes/conductor-javascript";

// Method 1: Using forkTask (creates only the fork)
// Method 1: Using forkTask (creates only the fork).
// Each inner array is one branch; the branches run in parallel.
const task1 = forkTask("fork_ref", [
simpleTask("task1", "process_1", {}),
simpleTask("task2", "process_2", {}),
simpleTask("task3", "process_3", {}),
[simpleTask("task1", "process_1", {})],
[simpleTask("task2", "process_2", {}), simpleTask("task3", "process_3", {})],
]);

// Method 2: Using forkTaskJoin (creates both fork and join)
Expand Down
7 changes: 7 additions & 0 deletions src/sdk/builders/tasks/__tests__/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ describe("forkTask", () => {
],
});
});
it("Should create one branch per inner list", () => {
const a = eventTask("a", "prefix", "suffix");
const b = eventTask("b", "prefix", "suffix");
const c = eventTask("c", "prefix", "suffix");
const forkTaskObj = forkTask("parallel", [[a, b], [c]]);
expect(forkTaskObj.forkTasks).toEqual([[a, b], [c]]);
});
it("Should return a tuple with both fork and join", () => {
const tname = "forkTaskJoin";
const [forkTask, joinTask] = forkTaskJoin(tname, [
Expand Down
11 changes: 9 additions & 2 deletions src/sdk/builders/tasks/forkJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ import {
} from "../../../open-api";
import { generateJoinTask } from "../../generators";

/**
* Creates a FORK_JOIN task. Pass a list of branches (`TaskDefTypes[][]`) to run
* them in parallel; a flat list of tasks is treated as a single branch.
*/
export const forkTask = (
taskReferenceName: string,
forkTasks: TaskDefTypes[]
forkTasks: TaskDefTypes[] | TaskDefTypes[][]
): ForkJoinTaskDef => ({
taskReferenceName,
name: taskReferenceName,
type: TaskType.FORK_JOIN,
forkTasks: [forkTasks],
forkTasks:
forkTasks.length > 0 && forkTasks.every((branch) => Array.isArray(branch))
? (forkTasks as TaskDefTypes[][])
: [forkTasks as TaskDefTypes[]],
});

export const forkTaskJoin = (
Expand Down