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
SqlError::QueryTimeoutโ the query exceeded the configured timeout.SqlError::Connectionโ the database could not be reached (I/O, TLS, protocol, or connection pool failure).SqlError::Queryโ the underlying query failed for any other reason (e.g. syntax error).