Skip to content

fix(datastore): crash when insert cancellables #4956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/amplify_datastore/ios/Classes/FlutterApiPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import Foundation
import Flutter
import Combine



public class FlutterApiPlugin: APICategoryPlugin
{
public var key: PluginKey = "awsAPIPlugin"
private let apiAuthFactory: APIAuthProviderFactory
private let nativeApiPlugin: NativeApiPlugin
private let nativeSubscriptionEvents: PassthroughSubject<NativeGraphQLSubscriptionResponse, Never>
private var cancellables = Set<AnyCancellable>()
private var cancellables = AtomicDictionary<AnyCancellable, Void>()

init(
apiAuthProviderFactory: APIAuthProviderFactory,
Expand Down Expand Up @@ -82,7 +80,9 @@ public class FlutterApiPlugin: APICategoryPlugin
}
}
.toAmplifyAsyncThrowingSequence()
cancellables.insert(cancellable) // the subscription is bind with class instance lifecycle, it should be released when stream is finished or unsubscribed

cancellables.set(value: (), forKey: cancellable) // the subscription is bind with class instance lifecycle, it should be released when stream is finished or unsubscribed

sequence.send(.connection(.connecting))
DispatchQueue.main.async {
self.nativeApiPlugin.subscribe(request: request.toNativeGraphQLRequest()) { response in
Expand Down
Loading