Skip to content

Commit

Permalink
fix(datastore): Clear subscriptions on Stop (#5253)
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey authored Aug 12, 2024
1 parent 9c12c93 commit d59a804
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ public class SwiftAmplifyDataStorePlugin: NSObject, FlutterPlugin, NativeAmplify
onStart(flutterResult: result)
case "stop":
onStop(flutterResult: result)
DispatchQueue.main.async {
self.nativeApiPlugin.onStop {}
}
default:
result(FlutterMethodNotImplemented)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/amplify_datastore/lib/amplify_datastore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,14 @@ class NativeAmplifyApi
_subscriptionsCache.remove(subscriptionId);
}
}

/// Amplify.DataStore.Stop() callback
///
/// Clean up subscriptions on stop.
@override
Future<void> onStop() async {
_subscriptionsCache.forEach((subId, _) async {
await unsubscribe(subId);
});
}
}
16 changes: 16 additions & 0 deletions packages/amplify_datastore/lib/src/native_plugin.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/amplify_datastore/pigeons/native_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ abstract class NativeApiPlugin {

@async
void unsubscribe(String subscriptionId);

@async
void onStop();
}

/// Bridge for calling Amplify from Flutter into Native
Expand Down

0 comments on commit d59a804

Please sign in to comment.