-
Notifications
You must be signed in to change notification settings - Fork 2.3k
What does ensureInitialized actually do? And when should I use it? #7486
-
Hi FB team!
I wonder what does ensureInitialized actually stands for?
In the docs it says
Ensures the last activated config are available to the getters.
So I understand that it will be resolved as soon as activation is passed (In my code as soon as fetchAndActivate resolves I guess)
My remote config initialization looks like this
remoteConfig()
.setDefaults(REMOTE_CONFIG_DEFAULTS)
.then(() => {
return remoteConfig().setConfigSettings({
minimumFetchIntervalMillis: 0,
})
})
.then(() => remoteConfig().fetchAndActivate())
My read functions look like this
getSomeValue() {
await remoteConfig().ensureInitialized()
return remoteConfig().getString("someValueKey")
}
Question 1:
I don't understand why when I try to read a value before fetchAndActivate resolves, it simply reads empty strings.
It's strange because I use setDefaults for every value. And I expect getSomeValue to at least return a value from the defaults.
Question 2:
I see that in Android code ensureInitialized seems to await for fetchAndActivate
Task<FirebaseRemoteConfigInfo> ensureInitialized(String appName) {
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance(firebaseApp);
Task<FirebaseRemoteConfigInfo> ensureInitializedTask = config.ensureInitialized();
try {
Tasks.await(fetchAndActivate(appName));
} catch (Exception e) {
// do nothing
}
return ensureInitializedTask;
}
However for iOS I don't find similar implementation. Do ensureInitialized behave the same on both platforms?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I'm wrapping my head around how to better load remote config and these are the same questions I have.
Beta Was this translation helpful? Give feedback.