pub struct Runtime<S: State + Default> {
pub previous: Option<Value>,
pub checkpointer: Option<Arc<dyn CheckpointSaver>>,
pub store: Option<Arc<dyn Store>>,
pub core: Runtime<S>,
}Expand description
Runtime context for functional API workflows
Provides access to previous execution state, checkpointing, and storage
during workflow execution. This type extends CoreRuntime with
functional-API-specific features like previous value access.
§Type Parameters
§Fields
previous- Previous execution return value (for accumulation patterns)checkpointer- Checkpoint saver for state persistencestore- Cross-thread persistent key-value storecore- Underlying core runtime for advanced use cases
§Examples
§Accessing previous state
use juncture_core::func::Runtime;
async fn accumulating_workflow(
state: CowState<MyState>,
runtime: &CoreRuntime<MyState>,
) -> Result<MyStateUpdate, JunctureError> {
// Access the functional runtime
let func_runtime = Runtime::from_core(runtime);
// Get the previous return value
if let Some(previous) = &func_runtime.previous {
let prev_output: Output = serde_json::from_value(previous.clone())
.map_err(|e| JunctureError::execution(format!("Failed to deserialize previous: {}", e)))?;
// Use previous value for accumulation
}
Ok(MyStateUpdate::default())
}§Using the store
use juncture_core::func::Runtime;
async fn workflow_with_store(
state: CowState<MyState>,
runtime: &CoreRuntime<MyState>,
) -> Result<MyStateUpdate, JunctureError> {
let func_runtime = Runtime::from_core(runtime);
if let Some(store) = &func_runtime.store {
store.put("key", serde_json::json!("value")).await?;
}
Ok(MyStateUpdate::default())
}Fields§
§previous: Option<Value>Previous execution return value (for accumulation patterns)
When resuming from a checkpoint, this contains the return value from
the previous execution. For first-time execution, this is None.
checkpointer: Option<Arc<dyn CheckpointSaver>>Checkpoint saver for state persistence
When set, the workflow can save and restore intermediate state.
store: Option<Arc<dyn Store>>Cross-thread persistent key-value store
Provides durable storage that survives across workflow executions.
core: Runtime<S>Underlying core runtime
Provides access to advanced runtime features like heartbeat, execution metadata, and streaming.
Implementations§
Source§impl<S: State + Default> Runtime<S>
impl<S: State + Default> Runtime<S>
Sourcepub fn from_core(core: &CoreRuntime<S>) -> Self
pub fn from_core(core: &CoreRuntime<S>) -> Self
Create a functional runtime from a core runtime
This extracts functional-API-specific context from the core runtime, allowing entrypoint functions to access features like previous values.
Sourcepub fn from_entrypoint_config(config: &EntrypointConfig) -> Selfwhere
S: Default,
pub fn from_entrypoint_config(config: &EntrypointConfig) -> Selfwhere
S: Default,
Create a runtime from an entrypoint configuration
Sourcepub fn with_previous(self, previous: Value) -> Self
pub fn with_previous(self, previous: Value) -> Self
Set the previous execution value
Sourcepub fn with_checkpointer(self, checkpointer: Arc<dyn CheckpointSaver>) -> Self
pub fn with_checkpointer(self, checkpointer: Arc<dyn CheckpointSaver>) -> Self
Set the checkpointer
Sourcepub fn with_store(self, store: Arc<dyn Store>) -> Self
pub fn with_store(self, store: Arc<dyn Store>) -> Self
Set the store
Sourcepub fn with_core(self, core: CoreRuntime<S>) -> Self
pub fn with_core(self, core: CoreRuntime<S>) -> Self
Set the core runtime