diff --git a/src/dfx/src/commands/start.rs b/src/dfx/src/commands/start.rs index affe6d54c5..8dc1ffbc9b 100644 --- a/src/dfx/src/commands/start.rs +++ b/src/dfx/src/commands/start.rs @@ -10,6 +10,7 @@ use crate::lib::replica_config::ReplicaConfig; use clap::{App, Arg, ArgMatches, SubCommand}; use crossbeam::channel::{Receiver, Sender}; use crossbeam::unbounded; +use delay::{Delay, Waiter}; use futures::future::Future; use ic_agent::{Agent, AgentConfig}; use indicatif::{ProgressBar, ProgressDrawTarget}; @@ -56,14 +57,24 @@ fn ping_and_wait(frontend_url: &str) -> DfxResult { })?; // wait for frontend to come up - use std::{thread, time}; - let three_secs = time::Duration::from_secs(3); - thread::sleep(three_secs); - - runtime - .block_on(agent.status()) - .map(|_| ()) - .map_err(DfxError::from) + let mut waiter = Delay::builder() + .timeout(std::time::Duration::from_secs(30)) + .throttle(std::time::Duration::from_secs(1)) + .build(); + + runtime.block_on(async { + waiter.start(); + loop { + let status = agent.status().await; + if status.is_ok() { + break; + } + waiter + .wait() + .map_err(|_| DfxError::AgentError(status.unwrap_err()))?; + } + Ok(()) + }) } // TODO(eftychis)/In progress: Rename to replica.