Skip to main content

Break Workflow Activity

This activity is used to break the execution of the loop activity.

import { Step } from 'sequential-workflow-model';
import { createBreakActivity, break_ } from 'sequential-workflow-machine';

interface BreakStep extends Step {
/* ... */
}

const breakActivity = createBreakActivity<BreakStep, MyGlobalState, MyActivityState>('break', {
init: (step: BreakStep, globalState: MyGlobalState) => ({ /* creates activity state */ }),
loopName: (step: BreakStep) => `FOR_${step.id}`,
handler: async (step: BreakStep, globalState: MyGlobalState, activityState: MyActivityState) => {
if (/* ... */) {
return break_();
}
// if we don't call the `break_()` function, the loop will continue.
}
});

If you don't know the name of the parent step the loopName callback can return -1. In this case the break activity will break the execution of the first loop it finds in the parent steps.

loopName: (step: BreakStep) => -1,