Conditional and Branching Flows Example
This example demonstrates how to implement conditional logic and branching in ZoopFlow to create dynamic workflows that adapt based on input data and runtime conditions.
What You'll Learn
- How to implement if/else logic in flows
- How to create dynamic branches based on conditions
- How to use switch-case patterns for multiple conditions
- How to implement loop constructs for repeated execution
- How to combine conditional logic with error handling
Files in this Example
conditional-flow.ts- Demonstrates basic if/else conditional flowswitch-case-flow.ts- Shows implementing switch-case pattern for multiple branchesdynamic-branching.ts- Implements dynamic routing based on runtime dataloop-example.ts- Shows how to implement loop constructsrun-example.ts- Entry point to run the example
Conditional Flow Concepts
In ZoopFlow, conditional flows:
- Allow dynamic paths of execution based on conditions
- Enable complex business logic implementation
- Support runtime decision making
- Can branch to different steps based on input or computed values
- Can express conditions using simple JavaScript expressions
How to Run
# From the project root
npm install
npx ts-node docs/new-structure/examples/conditional-flows/run-example.tsExpected Output
The example will:
- Demonstrate a simple if/else branch based on input
- Show a switch-case pattern with multiple execution paths
- Implement dynamic branching based on runtime data
- Execute a loop construct until a condition is met
Output will show the different paths taken in each flow execution.
Next Steps
- Create more complex conditional flows for real business logic
- Combine conditional flows with error handling
- Implement parallel execution with conditions
- Explore integration with Temporal for durable conditional flows