Skip to main content

Mountain/Vine/Client/
WaitForClientConnection.rs

1#![allow(non_snake_case)]
2
3//! Poll `IsClientConnected` every 50 ms until the sidecar appears in
4//! the pool or the budget runs out. `BudgetMilliseconds` is a soft upper
5//! bound; user-facing call paths should keep it under ~1500 ms.
6
7use std::time::{Duration, Instant};
8
9use crate::Vine::Client::{IsClientConnected, IsShuttingDown};
10
11pub async fn Fn(SideCarIdentifier:&str, BudgetMilliseconds:u64) -> bool {
12	if IsClientConnected::Fn(SideCarIdentifier) {
13		return true;
14	}
15	let Deadline = Instant::now() + Duration::from_millis(BudgetMilliseconds);
16	while Instant::now() < Deadline {
17		tokio::time::sleep(Duration::from_millis(50)).await;
18		if IsClientConnected::Fn(SideCarIdentifier) {
19			return true;
20		}
21		if IsShuttingDown::Fn() {
22			return false;
23		}
24	}
25	IsClientConnected::Fn(SideCarIdentifier)
26}