Skip to content

Commit

Permalink
ping/rust: publish own message before subscribing
Browse files Browse the repository at this point in the history
  • Loading branch information
elenaf9 committed Sep 27, 2022
1 parent 92d2073 commit 210007f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions ping/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
e => panic!("Unexpected event {:?}", e),
}

let payload = serde_json::json!({
"ID": swarm.local_peer_id().to_string(),
"Addrs": [
local_addr.to_string(),
],
});

client.publish("peers", Cow::Owned(payload)).await?;

let test_instance_count = client.run_parameters().test_instance_count as usize;
let mut address_stream = client
.subscribe("peers", test_instance_count)
Expand All @@ -104,15 +113,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// We can do this because sync service pubsub is ordered.
.take_while(|a| ready(a != &local_addr));

let payload = serde_json::json!({
"ID": swarm.local_peer_id().to_string(),
"Addrs": [
local_addr.to_string(),
],
});

client.publish("peers", Cow::Owned(payload)).await?;

while let Some(addr) = address_stream.next().await {
swarm.dial(addr).unwrap();
}
Expand Down

0 comments on commit 210007f

Please sign in to comment.