Skip to main content

run_with_timeout

Function run_with_timeout 

Source
pub async fn run_with_timeout<F, T>(
    timeout: Option<Duration>,
    fut: F,
) -> Result<T, RdbmsError>
where F: Future<Output = Result<T, RdbmsError>>,
Expand description

给数据库调用套一层超时。

None 表示禁用超时,直接透传结果。超时发生时递增 QUERY_TIMEOUTS 并返回 RdbmsError::Timeout。

这是池耗尽的头号防线:acquire_timeout 只约束「等连接」, 拿到连接后卡死的查询会一直占着它。