Skip to main content

Fork Workflow Activity

This activity is used to fork the execution of the workflow. You can use it to realize a condition statement or a switch statement.

import { BranchedStep } from 'sequential-workflow-model';
import { createForkActivity, interrupt, branchName } from 'sequential-workflow-machine';

interface IfStep extends BranchedStep {
type: 'if';
componentType: 'switch';
/* ... */
}

const ifActivity = createForkActivity<IfStep, MyGlobalState, MyActivityState>('if', {
init: () => {
return {}; // Initial activity state
},
handler: async (step: IfStep, globalState: MyGlobalState, activityState: MyActivityState) => {
if (globalState.temperature < 0) {
return interrupt();
}
if (globalState.temperature > 10) {
return branchName('true');
}
return branchName('false');
}
});