Skip to content

Commit d59a804

Browse files
authored
fix(datastore): Clear subscriptions on Stop (#5253)
1 parent 9c12c93 commit d59a804

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/pigeons/NativePluginBindings.kt

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/amplify_datastore/ios/Classes/SwiftAmplifyDataStorePlugin.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ public class SwiftAmplifyDataStorePlugin: NSObject, FlutterPlugin, NativeAmplify
234234
onStart(flutterResult: result)
235235
case "stop":
236236
onStop(flutterResult: result)
237+
DispatchQueue.main.async {
238+
self.nativeApiPlugin.onStop {}
239+
}
237240
default:
238241
result(FlutterMethodNotImplemented)
239242
}

packages/amplify_datastore/ios/Classes/pigeons/NativePluginBindings.swift

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/amplify_datastore/lib/amplify_datastore.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,14 @@ class NativeAmplifyApi
375375
_subscriptionsCache.remove(subscriptionId);
376376
}
377377
}
378+
379+
/// Amplify.DataStore.Stop() callback
380+
///
381+
/// Clean up subscriptions on stop.
382+
@override
383+
Future<void> onStop() async {
384+
_subscriptionsCache.forEach((subId, _) async {
385+
await unsubscribe(subId);
386+
});
387+
}
378388
}

packages/amplify_datastore/lib/src/native_plugin.g.dart

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/amplify_datastore/pigeons/native_plugin.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ abstract class NativeApiPlugin {
4141

4242
@async
4343
void unsubscribe(String subscriptionId);
44+
45+
@async
46+
void onStop();
4447
}
4548

4649
/// Bridge for calling Amplify from Flutter into Native

0 commit comments

Comments
 (0)