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
else {
subscriptionItem.subscriptionEventHandler(.failed(error), subscriptionItem)
connectionProvider?.removeListener(identifier: subscriptionItem.identifier)
return
}
@ -43,6 +44,7 @@ extension AppSyncSubscriptionConnection {
}
} else {
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
var retryHandler: ConnectionRetryHandler?
let serialQueue = DispatchQueue(
label: "com.amazonaws.AppSyncSubscriptionConnection.serialQueue"
)
public init(provider: ConnectionProvider) {
self.connectionProvider = provider
}
@ -84,6 +88,7 @@ public class AppSyncSubscriptionConnection: SubscriptionConnection, RetryableCon
AppSyncLogger.debug("[AppSyncSubscriptionConnection] \(#function): Self is nil, listener is not called.")
return
}
self.serialQueue.async {
switch event {
case .connection(let state):
self.handleConnectionEvent(connectionState: state)
@ -94,6 +99,7 @@ public class AppSyncSubscriptionConnection: SubscriptionConnection, RetryableCon
}
}
}
}
public func addRetryHandler(handler: ConnectionRetryHandler) {
retryHandler = handler