Skip to content

Commit 8d8cd21

Browse files
committed
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.
1 parent d51bcc8 commit 8d8cd21

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ bip39 = "2.0.0"
7373

7474
rand = "0.8.5"
7575
chrono = { version = "0.4", default-features = false, features = ["clock"] }
76-
futures = "0.3"
7776
tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "time", "sync" ] }
7877
esplora-client = { version = "0.6", default-features = false }
7978
libc = "0.2"

src/connection.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ where
4747
Some(connection_closed_future) => {
4848
let mut connection_closed_future = Box::pin(connection_closed_future);
4949
loop {
50-
match futures::poll!(&mut connection_closed_future) {
51-
std::task::Poll::Ready(_) => {
50+
tokio::select! {
51+
_ = &mut connection_closed_future => {
5252
log_info!(logger, "Peer connection closed: {}@{}", node_id, addr);
5353
return Err(Error::ConnectionFailed);
5454
},
55-
std::task::Poll::Pending => {},
56-
}
57-
// Avoid blocking the tokio context by sleeping a bit
55+
_ = tokio::time::sleep(Duration::from_millis(10)) => {},
56+
};
57+
5858
match peer_manager.peer_by_node_id(&node_id) {
5959
Some(_) => return Ok(()),
60-
None => tokio::time::sleep(Duration::from_millis(10)).await,
60+
None => continue,
6161
}
6262
}
6363
},

0 commit comments

Comments
 (0)