Skip to main content

execute_with_timeout

Function execute_with_timeout 

Source
pub async fn execute_with_timeout<T>(
    timeout_secs: Option<u64>,
    sql: SqlStr,
    op: impl AsyncFnOnce(SqlStr) -> Result<T, Error>,
) -> Result<T, SqlError>
Expand description

Runs a query operation with an optional query timeout.

op is handed the SqlStr to execute and returns the in-flight query future. When timeout_secs is Some(n) with n > 0, that future is wrapped with tokio::time::timeout; on expiry it is dropped (cancelling the in-flight query) and SqlError::QueryTimeout is returned with the elapsed time and the SQL text. None or Some(0) runs without a timeout.

The SQL text is only copied into the error on the timeout path, so the success path adds no allocation.

§Errors