diff --git a/client/src-tauri/src/telemetry/create_subscription.rs b/client/src-tauri/src/telemetry/create_subscription.rs index 6442707..c9ab0b5 100644 --- a/client/src-tauri/src/telemetry/create_subscription.rs +++ b/client/src-tauri/src/telemetry/create_subscription.rs @@ -14,7 +14,9 @@ use tokio::time::{sleep, Duration}; /// /// This function will retry creating a subscription every 3 seconds /// if it fails. -pub async fn create_subscription(client: &Client) -> Subscription { +pub async fn create_subscription(client: &Client) -> Result { + let mut attempts: u8 = 0; + loop { let subscription_attempt = client .subscribe_w_options( @@ -28,12 +30,17 @@ pub async fn create_subscription(client: &Client) -> Subscription { .await; match subscription_attempt { - Ok(subscription) => break subscription, + Ok(subscription) => break Ok(subscription), Err(e) => { if cfg!(debug_assertions) { println!("Failed to create subscription: {}", e); } + if attempts >= 50 { + break Err(e); + } + + attempts += 1; sleep(Duration::from_secs(3)).await; // Wait for 3 seconds before retrying continue; }