Skip to content

Commit

Permalink
Use tokio::select on connection_closed_future
Browse files Browse the repository at this point in the history
.. which is a bit more readable and in-line what we do other places,
plus it allows us to drop the `futures` dependency.
  • Loading branch information
tnull committed Mar 12, 2024
1 parent a09e245 commit b3151cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
},
Expand Down

0 comments on commit b3151cd

Please sign in to comment.