pub async fn execute_with_timeout<T, E: Display>(
timeout_secs: Option<u64>,
sql: &str,
fut: impl Future<Output = Result<T, E>>,
) -> Result<T, AppError>Expand description
Executes fut with an optional query timeout.
When timeout_secs is Some(n) where n > 0, the future is wrapped
with tokio::time::timeout. On expiry the future is dropped
(cancelling the in-flight query) and AppError::QueryTimeout is
returned with the wall-clock elapsed time and the original SQL text.
When timeout_secs is None or Some(0), the future runs without
any timeout.
§Errors
AppError::QueryTimeout— the query exceeded the configured timeout.AppError::Query— the underlying query failed for a non-timeout reason (e.g. syntax error, connection loss).