From f9802839805ad4f04838039bb9a53a3a23674850 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Tue, 14 Nov 2023 05:47:51 -0500 Subject: [PATCH] fix serial queue logic --- .../Starscream/StarscreamAdapter.swift | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/AppSyncRealTimeClient/Websocket/Starscream/StarscreamAdapter.swift b/AppSyncRealTimeClient/Websocket/Starscream/StarscreamAdapter.swift index 3ff0052e..b7400c9d 100644 --- a/AppSyncRealTimeClient/Websocket/Starscream/StarscreamAdapter.swift +++ b/AppSyncRealTimeClient/Websocket/Starscream/StarscreamAdapter.swift @@ -53,27 +53,29 @@ public class StarscreamAdapter: AppSyncWebsocketProvider { self.socket?.callbackQueue = self.callbackQueue self.socket?.connect() #if os(watchOS) - // On watchOS, if it takes longer than 5 seconds - // to connect, fail fast. AppSyncLogger.debug( - "[StarscreamAdapter] Starting connectivity timer for watchOS for 3s" + "[StarscreamAdapter] Starting connectivity timer for watchOS for 3s." ) self.watchOSConnectivityTimer.start(interval: 3) { AppSyncLogger.debug( "[StarscreamAdapter] watchOS connectivity timer is up." ) - if !self._isConnected { - AppSyncLogger.debug( - "[StarscreamAdapter] watchOS subscriptions not connected after 3s." - ) - self.serialQueue.async { + self.serialQueue.async { + if !self._isConnected { + AppSyncLogger.debug( + "[StarscreamAdapter] watchOS subscriptions not connected after 3s." + ) + AppSyncLogger.debug( + "[StarscreamAdapter] Manually send disconnect." + ) self.delegate?.websocketDidDisconnect(provider: self, error: nil) + } else { + AppSyncLogger.debug( + "[StarscreamAdapter] watchOS subscriptions are connected within 3s." + ) } - } else { - AppSyncLogger.debug( - "[StarscreamAdapter] watchOS subscriptions are connected within 3s." - ) } + } #endif }