Compare commits

...

1 Commits

Author SHA1 Message Date
Michael Law 63d2cac4c1 fix: Subscription message handling - serial queue and stop after failed event 2022-02-16 16:03:28 -05:00
2 changed files with 15 additions and 7 deletions

View File

@ -32,6 +32,7 @@ extension AppSyncSubscriptionConnection {
let connectionError = error as? ConnectionProviderError let connectionError = error as? ConnectionProviderError
else { else {
subscriptionItem.subscriptionEventHandler(.failed(error), subscriptionItem) subscriptionItem.subscriptionEventHandler(.failed(error), subscriptionItem)
connectionProvider?.removeListener(identifier: subscriptionItem.identifier)
return return
} }
@ -43,6 +44,7 @@ extension AppSyncSubscriptionConnection {
} }
} else { } else {
subscriptionItem.subscriptionEventHandler(.failed(error), subscriptionItem) subscriptionItem.subscriptionEventHandler(.failed(error), subscriptionItem)
connectionProvider?.removeListener(identifier: subscriptionItem.identifier)
} }
} }

View File

@ -28,6 +28,10 @@ public class AppSyncSubscriptionConnection: SubscriptionConnection, RetryableCon
/// Retry logic to handle /// Retry logic to handle
var retryHandler: ConnectionRetryHandler? var retryHandler: ConnectionRetryHandler?
let serialQueue = DispatchQueue(
label: "com.amazonaws.AppSyncSubscriptionConnection.serialQueue"
)
public init(provider: ConnectionProvider) { public init(provider: ConnectionProvider) {
self.connectionProvider = provider self.connectionProvider = provider
} }
@ -84,6 +88,7 @@ public class AppSyncSubscriptionConnection: SubscriptionConnection, RetryableCon
AppSyncLogger.debug("[AppSyncSubscriptionConnection] \(#function): Self is nil, listener is not called.") AppSyncLogger.debug("[AppSyncSubscriptionConnection] \(#function): Self is nil, listener is not called.")
return return
} }
self.serialQueue.async {
switch event { switch event {
case .connection(let state): case .connection(let state):
self.handleConnectionEvent(connectionState: state) self.handleConnectionEvent(connectionState: state)
@ -94,6 +99,7 @@ public class AppSyncSubscriptionConnection: SubscriptionConnection, RetryableCon
} }
} }
} }
}
public func addRetryHandler(handler: ConnectionRetryHandler) { public func addRetryHandler(handler: ConnectionRetryHandler) {
retryHandler = handler retryHandler = handler