Skip to content

Commit 9b3ef22

Browse files
authored
Merge pull request #880 from hatoo/refactor-timeout
refactor: replace tokio::select with tokio::time::timeout for request…
2 parents 339ec32 + 0efa702 commit 9b3ef22

2 files changed

Lines changed: 9 additions & 21 deletions

File tree

src/client.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -776,13 +776,9 @@ impl Client {
776776
};
777777

778778
if let Some(timeout) = self.timeout {
779-
tokio::select! {
780-
res = do_req => {
781-
res
782-
}
783-
_ = tokio::time::sleep(timeout) => {
784-
Err(ClientError::Timeout)
785-
}
779+
match tokio::time::timeout(timeout, do_req).await {
780+
Ok(res) => res,
781+
Err(_) => Err(ClientError::Timeout),
786782
}
787783
} else {
788784
do_req.await
@@ -923,13 +919,9 @@ impl Client {
923919
};
924920

925921
if let Some(timeout) = self.timeout {
926-
tokio::select! {
927-
res = do_req => {
928-
res
929-
}
930-
_ = tokio::time::sleep(timeout) => {
931-
Err(ClientError::Timeout)
932-
}
922+
match tokio::time::timeout(timeout, do_req).await {
923+
Ok(res) => res,
924+
Err(_) => Err(ClientError::Timeout),
933925
}
934926
} else {
935927
do_req.await

src/client_h3.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,9 @@ impl Client {
175175
};
176176

177177
if let Some(timeout) = self.timeout {
178-
tokio::select! {
179-
res = do_req => {
180-
res
181-
}
182-
_ = tokio::time::sleep(timeout) => {
183-
Err(ClientError::Timeout)
184-
}
178+
match tokio::time::timeout(timeout, do_req).await {
179+
Ok(res) => res,
180+
Err(_) => Err(ClientError::Timeout),
185181
}
186182
} else {
187183
do_req.await

0 commit comments

Comments
 (0)