Skip to main content

Loop Workflow Activity

This activity is used to execute a step with a subsequence of steps (SequentialStep) in a loop. You can create a while, do-while, for or foreach loop by this activity.

import { SequentialStep } from 'sequential-workflow-model';
import { createLoopActivity } from 'sequential-workflow-machine';

interface ForStep extends SequentialStep {
type: 'for';
componentType: 'loop';
/* ... */
}

const forActivity = createLoopActivity<ForStep, MyGlobalState, MyActivityState>('for', {
loopName: step => `FOR_${step.id}`,
init: step => { /* ... */ },
onEnter: async (step: ForStep, globalState: MyGlobalState, activityState: MyActivityState) => {
/* ... */
},
onLeave: async (step: ForStep, globalState: MyGlobalState, activityState: MyActivityState) => {
/* ... */
},
condition: async (step: ForStep, globalState: MyGlobalState, activityState: MyActivityState) => {
return true; // `false` if the loop should be stopped
}
});