MCPcopy Create free account
hub / github.com/aeroxy/chrome-devtools-cli / wait_for_daemon

Function wait_for_daemon

src/client.rs:61–84  ·  view source on GitHub ↗

Wait for the daemon socket to become available, with exponential backoff.

()

Source from the content-addressed store, hash-verified

59
60/// Wait for the daemon socket to become available, with exponential backoff.
61pub async fn wait_for_daemon() -> Result<()> {
62 let deadline = tokio::time::Instant::now() + daemon_wait_timeout();
63 let mut delay = Duration::from_millis(50);
64 loop {
65 if tokio::time::Instant::now() > deadline {
66 bail!(
67 "Daemon failed to start within {} seconds",
68 daemon_wait_timeout().as_secs()
69 );
70 }
71 if connect_daemon().await.is_ok() {
72 return Ok(());
73 }
74 // Simple jitter based on current time subseconds
75 let jitter = SystemTime::now()
76 .duration_since(SystemTime::UNIX_EPOCH)
77 .map(|d| {
78 Duration::from_millis(d.subsec_nanos() as u64 % (delay.as_millis() as u64 + 1))
79 })
80 .unwrap_or_default();
81 tokio::time::sleep(delay + jitter).await;
82 delay = (delay * 2).min(Duration::from_millis(500));
83 }
84}

Callers 1

runFunction · 0.85

Calls 2

daemon_wait_timeoutFunction · 0.85
connect_daemonFunction · 0.85

Tested by

no test coverage detected