This directory contains examples demonstrating how to separate data preparation from script evaluation in go-polyscript.
The data preparation pattern separates static configuration data from dynamic runtime data, making code more modular and flexible. This pattern uses a composite data provider combining static and dynamic data sources, with a clear separation between configuration, preparation, and evaluation phases.
This pattern is valuable for:
- Distributed Architecture: Prepare data on one system (e.g., web server) and evaluate on another (e.g., worker)
- Separation of Concerns: Clearly separate data processing from script execution
- Layered Data Access: Combine static configuration with dynamic runtime data
- Performance Optimization: Prepare data asynchronously while other operations are happening
These examples follow a consistent three-phase pattern:
- Create evaluator with static data: Set up an evaluator with configuration data that remains constant across executions
- Prepare runtime data: Add dynamic data to the context using the
AddDataToContext
method - Evaluate script: Execute the script with the enriched context
Each example follows the same pattern but demonstrates it with a different script engine:
go run examples/data-prep/<engine>/main.go
Note: The Extism example requires a WASM file. If not found automatically, you may need to compile it using the Makefile
in /engines/extism/testdata/
.
- Simple Examples: Basic one-time execution pattern
- Multiple Instantiation Examples: Compile-once-run-many pattern