From 33d07c45a8e159bbead078a0cbe98be3e7188e8d Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Tue, 27 Apr 2021 20:15:21 -0500 Subject: [PATCH] :recycle: refactor: use `tokio::time::timeout` --- crates/ptth_relay/src/lib.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/ptth_relay/src/lib.rs b/crates/ptth_relay/src/lib.rs index 8f49341..136e004 100644 --- a/crates/ptth_relay/src/lib.rs +++ b/crates/ptth_relay/src/lib.rs @@ -144,15 +144,14 @@ async fn handle_http_request ( state.park_client (server_name, req, &req_id).await; - let timeout = tokio::time::sleep (std::time::Duration::from_secs (30)); - - let received = tokio::select! { - val = rx => val, - () = timeout => { + let received = match tokio::time::timeout (Duration::from_secs (30), rx).await + { + Ok (x) => x, + Err (_) => { debug! ("Timed out request {}", req_id); - return error_reply (StatusCode::GATEWAY_TIMEOUT, "Remote server never responded") - }, - }; + return error_reply (StatusCode::GATEWAY_TIMEOUT, "Remote server never responded"); + } + }; // UKAUFFY4 (Receive half) match received {