Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Oct 23, 2023
1 parent 4db7520 commit 5e73665
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions crates/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ provider = { path = "../provider" }
# to review the exports for neeeded types
support = { path = "../support" }
tokio = { workspace = true }
futures = { workspace = true }
4 changes: 3 additions & 1 deletion crates/examples/examples/simple_network_example.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// use std::time::Duration;

use configuration::NetworkConfig;
use futures::stream::StreamExt;
use orchestrator::Orchestrator;
use provider::NativeProvider;
use support::{fs::local::LocalFileSystem, process::os::OsProcessManager};
Expand All @@ -18,7 +19,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🚀🚀🚀🚀 network deployed");

let client = network.get_node("alice")?.client();
let mut blocks = client.blocks().subscribe_finalized().await?;
let mut blocks = client.blocks().subscribe_finalized().await?.take(3);

while let Some(block) = blocks.next().await {
println!("Block #{}", block?.header().number);
}
Expand Down
12 changes: 6 additions & 6 deletions crates/orchestrator/src/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ where
println!("📓 logs cmd: tail -f {}/{}.log", base_dir, node.name);
println!("\n");

let client = retry(|| async { OnlineClient::from_url(&ws_uri).await })
let client = retry(5, || async { OnlineClient::from_url(&ws_uri).await })
.await
.context(format!("Failed to connect to node rpc at {ws_uri}"))?;

Expand All @@ -182,18 +182,18 @@ where
))
}

async fn retry<T, F, R, E>(connect: F) -> Result<R, E>
async fn retry<T, F, R, E>(retry_count: u32, connect: F) -> Result<R, E>
where
T: Future<Output = Result<R, E>>,
F: Fn() -> T,
{
let mut retries = 5;
let mut failed_count = 0;
loop {
match connect().await {
Err(_) if retries >= 0 => {
println!("Error connecting, retrying ...");
Err(_) if retry_count > failed_count => {
failed_count += 1;
println!("Error connecting, retrying {failed_count}/{retry_count} ...");
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
retries -= 1;
},
res => break res,
}
Expand Down

0 comments on commit 5e73665

Please sign in to comment.