Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

What does ensureInitialized actually do? And when should I use it? #7486

Unanswered
KirillRodichevUtorg asked this question in Q&A
Discussion options

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?

You must be logged in to vote

Replies: 1 comment

Comment options

I'm wrapping my head around how to better load remote config and these are the same questions I have.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /