From 0efa7021d63dbad7f980e0eb735f452699abd3dc Mon Sep 17 00:00:00 2001 From: hatoo Date: Sat, 11 Apr 2026 17:17:41 +0900 Subject: [PATCH] refactor: replace tokio::select with tokio::time::timeout for request handling --- src/client.rs | 20 ++++++-------------- src/client_h3.rs | 10 +++------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/client.rs b/src/client.rs index 57e4e9b1..1509aa52 100644 --- a/src/client.rs +++ b/src/client.rs @@ -776,13 +776,9 @@ impl Client { }; if let Some(timeout) = self.timeout { - tokio::select! { - res = do_req => { - res - } - _ = tokio::time::sleep(timeout) => { - Err(ClientError::Timeout) - } + match tokio::time::timeout(timeout, do_req).await { + Ok(res) => res, + Err(_) => Err(ClientError::Timeout), } } else { do_req.await @@ -923,13 +919,9 @@ impl Client { }; if let Some(timeout) = self.timeout { - tokio::select! { - res = do_req => { - res - } - _ = tokio::time::sleep(timeout) => { - Err(ClientError::Timeout) - } + match tokio::time::timeout(timeout, do_req).await { + Ok(res) => res, + Err(_) => Err(ClientError::Timeout), } } else { do_req.await diff --git a/src/client_h3.rs b/src/client_h3.rs index b2b1f6d1..fedd58bc 100644 --- a/src/client_h3.rs +++ b/src/client_h3.rs @@ -175,13 +175,9 @@ impl Client { }; if let Some(timeout) = self.timeout { - tokio::select! { - res = do_req => { - res - } - _ = tokio::time::sleep(timeout) => { - Err(ClientError::Timeout) - } + match tokio::time::timeout(timeout, do_req).await { + Ok(res) => res, + Err(_) => Err(ClientError::Timeout), } } else { do_req.await