]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Drop `futures` dependency with `tokio::select`
authorMatt Corallo <git@bluematt.me>
Sun, 23 Apr 2023 17:03:57 +0000 (17:03 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 24 Apr 2023 03:26:29 +0000 (03:26 +0000)
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.

Cargo.toml
src/cli.rs

index 15c6c79104034cf6b066457263346cee2595baeb..9e83e5f5ff46d4aa5b02d2b480452bd83343799d 100644 (file)
@@ -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" }
index 9e5e20b1b9ec1df1abb56669e23d738b9fc2f40a..96d5d9d3c137eaabf97358d17d1d676a1dbdef87 100644 (file)
@@ -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(());
                                }
                        }
                }