From 605c5095f5d5ddc9981075a80257240974a589ad Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Thu, 4 Jan 2024 15:21:50 +0100 Subject: [PATCH] docs: Update README (#113) --- README.md | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 7c349ad0..61b7d471 100644 --- a/README.md +++ b/README.md @@ -29,36 +29,29 @@ Where `0.1.6` is the most recent version of this SDK. Released versions can be f ### Enabling the provider, setting the evaluation context and resolving flags - -`setProvider` makes the Provider reading the flags from the cache and launch a network request to refresh the flags. -In both cases of success or the failure of the network request, the `ProviderReady` signal will be emitted. -The `ProviderReady` event will be emitted only when we are done with the network request, either a successful or a failed network response. -If the network response is failed, we continue with the flags we have stored in the cache and emit the `ProviderReady`, if the network request -is successful we update the cache and then emit `ProviderReady`. - -The `awaitProviderReady()` suspend function is an utility function after which we can be sure about consistency of the flags. -flags are either loaded from the cache or refreshed from the network as explained above. - ```kotlin - OpenFeatureAPI.setProvider( - ConfidenceFeatureProvider.Builder( +coroutineScope.launch { + OpenFeatureAPI.setProviderAndWait( + ConfidenceFeatureProvider.create( applicationContext, - "mysecret" - ).build(), - ImmutableContext(targetingKey = "myTargetingKey") + "" + ), + dispatcher = Dispatchers.IO, + initialContext = ImmutableContext(targetingKey = "myTargetingKey") ) - -coroutineScope.launch { - awaitProviderReady() val result = client.getBooleanValue("flag.my-boolean", false) } ``` +`MY_SECRET` is an API key that can be generated in the [Confidence UI](https://confidence.spotify.com/console). + +The OpenFeature Event `ProviderReady` is also emitted when the provider is done initializing the cache. For more information on the OpenFeature APIs, follow the related [README](https://github.com/open-feature/kotlin-sdk?tab=readme-ov-file#usage). + ### Changing context after the provider initialization The evaluation context can be changed during the app session using `setEvaluationContext(...)`. After calling this method the new context is set for the provider and the flags will be fetched again and the cache and storage will be updated accordingly. -the `ProviderStale` and `ProviderReady` events will be emitted in order. +The OpenFeature Events `ProviderStale` and `ProviderReady` events will be emitted accordingly. Notes: -- If a flag can't be resolved from cache, the provider doesn't automatically resort to calling remote: refreshing the cache from remote only happens when setting a new provider and/or evaluation context in the global OpenFeatureAPI +- If a flag can't be resolved from cache, the provider does NOT automatically resort to calling remote: refreshing the cache from remote only happens when setting a new provider and/or evaluation context in the global OpenFeatureAPI - It's advised not to perform resolves while `setProvider` and `setEvaluationContext` are running: resolves might return the default value with reason `STALE` during such operations. \ No newline at end of file