DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Vine/Client/WaitForClientConnection.rs
1#![allow(non_snake_case)]
2
3//! Await Cocoon's gRPC connection without polling. `GetConnectionNotify`
4//! returns a shared `tokio::sync::Notify` that `ConnectToSideCar` fires
5//! once the handshake succeeds; `WaitForClientConnection` simply awaits
6//! it under `tokio::time::timeout`. If the sidecar is already connected
7//! when we enter (typical for the second-and-later callers) `notified()`
8//! returns immediately because `notify_waiters` has already fired.
9//!
10//! `BudgetMilliseconds` remains the hard cap so call sites keep their
11//! existing behaviour for the pathological "Cocoon never starts" case.
12
13use std::time::Duration;
14
15use crate::Vine::Client::{IsClientConnected, IsShuttingDown, Shared::GetConnectionNotify};
16
17pub async fn Fn(SideCarIdentifier:&str, BudgetMilliseconds:u64) -> bool {
18 if IsShuttingDown::Fn() {
19 return false;
20 }
21
22 if IsClientConnected::Fn(SideCarIdentifier) {
23 return true;
24 }
25
26 let Notifier = GetConnectionNotify(SideCarIdentifier);
27
28 let Result = tokio::time::timeout(Duration::from_millis(BudgetMilliseconds), Notifier.notified()).await;
29
30 if Result.is_err() {
31 // Budget expired - do a final check in case the connection landed
32 // in the window between notified() registering and the timeout.
33 return IsClientConnected::Fn(SideCarIdentifier);
34 }
35
36 // Woken by FireConnectionNotify - the client is now in the pool.
37 true
38}