From 5eb315615fd6004baff0f020023f56627f3fc15f Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 25 Aug 2019 11:50:37 -0700 Subject: [PATCH 1/4] Bump for release --- packages/firebase_remote_config/CHANGELOG.md | 5 +++++ packages/firebase_remote_config/pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/firebase_remote_config/CHANGELOG.md b/packages/firebase_remote_config/CHANGELOG.md index 30d482f3cc25..7bc7823f783f 100644 --- a/packages/firebase_remote_config/CHANGELOG.md +++ b/packages/firebase_remote_config/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.2.0+7 + +* Fix `Bad state: Future already completed` error when initially + calling `RemoteConfig.instance` multiple times in parallel. + ## 0.2.0+6 * Update documentation to reflect new repository location. diff --git a/packages/firebase_remote_config/pubspec.yaml b/packages/firebase_remote_config/pubspec.yaml index 7542f26a6b94..48de94cafc12 100644 --- a/packages/firebase_remote_config/pubspec.yaml +++ b/packages/firebase_remote_config/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Remote Config. Update your application re-releasing. author: Flutter Team homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_remote_config -version: 0.2.0+6 +version: 0.2.0+7 dependencies: flutter: From ae4db9a9181f2329cf70f24729ac3703907152bd Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 25 Aug 2019 11:51:01 -0700 Subject: [PATCH 2/4] Add test --- .../example/test_driver/firebase_remote_config.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart b/packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart index 2514b2a08a1d..8b778d36d8e6 100644 --- a/packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart +++ b/packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart @@ -39,5 +39,16 @@ void main() { ValueSource.valueStatic, ); }); + + test('doubleInstance', () async { + final List> futures = >[ + RemoteConfig.instance, + RemoteConfig.instance, + ]; + Future.wait(futures).then((List remoteConfigs) { + // Check that both returned Remote Config instances are the same. + expect(remoteConfigs[0], remoteConfigs[1]); + }); + }); }); } From 2e228e477b6b940ca1d6fbcd1a5b41ffe26386a8 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 25 Aug 2019 11:51:05 -0700 Subject: [PATCH 3/4] Rewrite implementation to avoid unnecessary platform calls --- packages/firebase_remote_config/lib/src/remote_config.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/firebase_remote_config/lib/src/remote_config.dart b/packages/firebase_remote_config/lib/src/remote_config.dart index ea8362eac265..161a2b5b1447 100644 --- a/packages/firebase_remote_config/lib/src/remote_config.dart +++ b/packages/firebase_remote_config/lib/src/remote_config.dart @@ -33,12 +33,12 @@ class RemoteConfig extends ChangeNotifier { /// Gets the instance of RemoteConfig for the default Firebase app. static Future get instance async { if (!_instanceCompleter.isCompleted) { - _getRemoteConfigInstance(); + _instanceCompleter.complete(await _getRemoteConfigInstance()); } return _instanceCompleter.future; } - static void _getRemoteConfigInstance() async { + static Future _getRemoteConfigInstance() async { final Map properties = await channel.invokeMapMethod('RemoteConfig#instance'); @@ -53,7 +53,7 @@ class RemoteConfig extends ChangeNotifier { instance._remoteConfigSettings = remoteConfigSettings; instance._parameters = _parseRemoteConfigParameters(parameters: properties['parameters']); - _instanceCompleter.complete(instance); + return instance; } static Map _parseRemoteConfigParameters( From e21316b29a6ae5656b0c533703b9be5a446ea221 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 25 Aug 2019 12:01:13 -0700 Subject: [PATCH 4/4] Revert integration test --- .../example/test_driver/firebase_remote_config.dart | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart b/packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart index 8b778d36d8e6..2514b2a08a1d 100644 --- a/packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart +++ b/packages/firebase_remote_config/example/test_driver/firebase_remote_config.dart @@ -39,16 +39,5 @@ void main() { ValueSource.valueStatic, ); }); - - test('doubleInstance', () async { - final List> futures = >[ - RemoteConfig.instance, - RemoteConfig.instance, - ]; - Future.wait(futures).then((List remoteConfigs) { - // Check that both returned Remote Config instances are the same. - expect(remoteConfigs[0], remoteConfigs[1]); - }); - }); }); }