State Management Example
This example demonstrates how to manage state within flows and steps in ZoopFlow. Proper state management is essential for building robust workflows that can track progress, store intermediate results, and maintain consistency.
What You'll Learn
- How to use the state management APIs in flows and steps
- How to store and retrieve state during workflow execution
- How to share state between different steps
- How to implement checkpoints in long-running workflows
- How to handle state in error scenarios
- Best practices for state management
Files in this Example
basic-state-management.ts- Demonstrates the fundamental state management APIsshared-state-flow.ts- Shows how to share state between stepscheckpoint-example.ts- Implements checkpoints in long-running workflowsstate-persistence.ts- Demonstrates state persistence across workflow executionsrun-example.ts- Entry point to run the example
State Management Concepts
In ZoopFlow, state management:
- Provides a key-value store for workflow data
- Automatically persists state during workflow execution
- Allows steps to communicate through shared state
- Supports checkpointing for long-running processes
- Ensures state consistency even in failure scenarios
How to Run
# From the project root
npm install
npx ts-node docs/new-structure/examples/state-management/run-example.tsExpected Output
The example will:
- Demonstrate basic state operations (get, set)
- Show how state is shared between steps
- Implement checkpoint-based processing for large data sets
- Illustrate state persistence across workflow interruptions
Output will show the state changes throughout flow execution.
Next Steps
- Implement your own state management patterns
- Explore advanced state management with transactions
- Learn about state management with Temporal in the Temporal Integration Example
- Implement state management in a real-world use case