From: Matt Corallo Date: Sun, 23 Apr 2023 17:03:57 +0000 (+0000) Subject: Drop `futures` dependency with `tokio::select` X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=a9b67530dd95bc1d2b0aa5f075efb6fa7c002d5f;p=ldk-sample Drop `futures` dependency with `tokio::select` Manually poll'ing a future every 10ms rather than selecting across it and a timer is less effecient, and certainly not worth taking a dependency to do. --- diff --git a/Cargo.toml b/Cargo.toml index 15c6c79..9e83e5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ bech32 = "0.8" hex = "0.3" libc = "0.2" -futures = "0.3" chrono = "0.4" rand = "0.4" serde_json = { version = "1.0" } diff --git a/src/cli.rs b/src/cli.rs index 9e5e20b..96d5d9d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -592,16 +592,12 @@ pub(crate) async fn do_connect_peer( 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(_) => { - return Err(()); - } - std::task::Poll::Pending => {} - } - // Avoid blocking the tokio context by sleeping a bit - match peer_manager.get_peer_node_ids().iter().find(|(id, _)| *id == pubkey) { - Some(_) => return Ok(()), - None => tokio::time::sleep(Duration::from_millis(10)).await, + tokio::select! { + _ = &mut connection_closed_future => return Err(()), + _ = tokio::time::sleep(Duration::from_millis(10)) => {}, + }; + if peer_manager.get_peer_node_ids().iter().find(|(id, _)| *id == pubkey).is_some() { + return Ok(()); } } }