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
16	let Deadline = Instant::now() + Duration::from_millis(BudgetMilliseconds);
17
18	while Instant::now() < Deadline {
19		tokio::time::sleep(Duration::from_millis(50)).await;
20
21		if IsClientConnected::Fn(SideCarIdentifier) {
22			return true;
23		}
24
25		if IsShuttingDown::Fn() {
26			return false;
27		}
28	}
29
30	IsClientConnected::Fn(SideCarIdentifier)
31}