Skip to content

Commit

Permalink
fix(datastore): Clear subscriptions on Stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey committed Aug 8, 2024
1 parent ff0e634 commit 1dc7e6f
Show file tree
Hide file tree
Showing 6 changed files with 45 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 @@ -612,6 +612,9 @@ public class SwiftAmplifyDataStorePlugin: NSObject, FlutterPlugin, NativeAmplify
error: error,
flutterResult: flutterResult)
case .success():
DispatchQueue.main.async {
self.nativeApiPlugin.onStop {}
}
print("Successfully stopped datastore cloud syncing")
flutterResult(nil)
}
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.

4 changes: 4 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,10 @@ 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 1dc7e6f

Please sign in to comment.