From b3151cd7e6434fb158f7e8af788e326755d9ae89 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 4 Mar 2024 11:30:30 +0100 Subject: [PATCH] Use `tokio::select` on `connection_closed_future` .. which is a bit more readable and in-line what we do other places, plus it allows us to drop the `futures` dependency. --- Cargo.toml | 1 - src/connection.rs | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bd756645d..75f221777 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,6 @@ bip39 = "2.0.0" rand = "0.8.5" chrono = { version = "0.4", default-features = false, features = ["clock"] } -futures = "0.3" tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "time", "sync" ] } esplora-client = { version = "0.6", default-features = false } libc = "0.2" diff --git a/src/connection.rs b/src/connection.rs index e281e61c2..7a93c1d8d 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -47,17 +47,17 @@ where Some(connection_closed_future) => { let mut connection_closed_future = Box::pin(connection_closed_future); loop { - match futures::poll!(&mut connection_closed_future) { - std::task::Poll::Ready(_) => { + tokio::select! { + _ = &mut connection_closed_future => { log_info!(logger, "Peer connection closed: {}@{}", node_id, addr); return Err(Error::ConnectionFailed); }, - std::task::Poll::Pending => {}, - } - // Avoid blocking the tokio context by sleeping a bit + _ = tokio::time::sleep(Duration::from_millis(10)) => {}, + }; + match peer_manager.peer_by_node_id(&node_id) { Some(_) => return Ok(()), - None => tokio::time::sleep(Duration::from_millis(10)).await, + None => continue, } } },