Skip to main content

execute_with_timeout

Function execute_with_timeout 

Source
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 reporting
  • run_timeout - Maximum duration the operation is allowed to run
  • operation - The async operation to execute; receives state and config
  • state - The input state passed to the operation
  • config - 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?;