pub async fn execute_with_timeout<S, F, Fut>(
node_name: &str,
run_timeout: Duration,
operation: F,
state: &S,
config: &RunnableConfig,
) -> Result<Command<S>, JunctureError>where
S: State,
F: FnOnce(&S, &RunnableConfig) -> Fut,
Fut: Future<Output = Result<Command<S>, JunctureError>>,Expand description
Execute an async operation with a timeout.
Wraps the provided operation in a tokio::time::timeout and returns
a [JunctureError::node_timeout] if the operation does not complete within
run_timeout. Inner node errors are passed through unchanged.
§Arguments
node_name- Name of the node for error reportingrun_timeout- Maximum duration the operation is allowed to runoperation- The async operation to execute; receives state and configstate- The input state passed to the operationconfig- Execution configuration passed through to the operation
§Errors
Returns [JunctureError::node_timeout] if the operation exceeds run_timeout.
Returns the inner error if the operation fails before the timeout.
§Examples
ⓘ
use juncture_core::graph::builder::execute_with_timeout;
use std::time::Duration;
let result = execute_with_timeout(
"my_node",
Duration::from_secs(30),
|state, config| my_node.call(state, config),
state,
&config,
).await?;