Skip to main content

with_timeout

Function with_timeout 

Source
pub async fn with_timeout<F, T>(future: F) -> Result<T, TimeoutError>
where F: Future<Output = T>,
Expand description

为外部 IO 操作添加默认超时保护(P1-SEC-06)

默认超时 5 秒,对齐项目规则 “任何外部 IO 必须包裹在 tokio::time::timeout(默认 5s)中”。

§用法

let result = with_timeout(async {
    pool.acquire().await?.query(sql).await
}).await;