Skip to content

Commit

Permalink
Remove ready flag for gossipping
Browse files Browse the repository at this point in the history
  • Loading branch information
adzialocha committed Dec 8, 2024
1 parent a38738a commit c54269b
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/network.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock, RwLockWriteGuard};

use anyhow::Result;
Expand Down Expand Up @@ -51,7 +50,7 @@ impl TextDocumentStore {
}

pub fn write(&self) -> RwLockWriteGuard<TextDocumentStoreInner> {
self.inner.write().expect("can get write lock")
self.inner.write().expect("acquire write lock")
}
}

Expand Down Expand Up @@ -124,15 +123,10 @@ pub fn run() -> Result<(
.await
.expect("subscribe to topic");

let is_gossip_ready = Arc::new(AtomicBool::new(false));
{
let is_gossip_ready = is_gossip_ready.clone();
tokio::task::spawn(async move {
let _ = ready.await;
is_gossip_ready.store(true, Ordering::Relaxed);
println!("network joined!");
});
}
tokio::task::spawn(async move {
let _ = ready.await;
println!("network joined!");
});

// Task for handling operations arriving from the network.
let operations_store_clone = operations_store.clone();
Expand Down Expand Up @@ -236,13 +230,11 @@ pub fn run() -> Result<(
let encoded_gossip_operation = encode_gossip_operation(header, body)?;

// Broadcast operation on gossip overlay.
if is_gossip_ready.load(Ordering::Relaxed) {
topic_tx
.send(ToNetwork::Message {
bytes: encoded_gossip_operation,
})
.await?;
}
topic_tx
.send(ToNetwork::Message {
bytes: encoded_gossip_operation,
})
.await?;
}

Ok(())
Expand Down

0 comments on commit c54269b

Please sign in to comment.