then()

The then method creates a sequential dependency between workflow steps, ensuring steps execute in a specific order.

Usage

workflow
  .step(stepOne)
  .then(stepTwo)
  .then(stepThree);

Parameters

step:

Step | string
The step instance or step ID that should execute after the previous step completes

Returns

workflow:

Workflow
The workflow instance for method chaining

Validation

When using then:

  • The previous step must exist in the workflow
  • Steps cannot form circular dependencies
  • Each step can only appear once in a sequential chain

Error Handling

try {
  workflow
    .step(stepA)
    .then(stepB)
    .then(stepA) // Will throw error - circular dependency
    .commit();
} catch (error) {
  if (error instanceof ValidationError) {
    console.log(error.type); // 'circular_dependency'
    console.log(error.details);
  }
}

MIT 2025 © Nextra.