Skip to content

Commit

Permalink
docs: Update README (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria authored Jan 4, 2024
1 parent c776fe5 commit 605c509
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,29 @@ Where `0.1.6` is the most recent version of this SDK. Released versions can be f
<!---x-release-please-end-->

### 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")
"<MY_SECRET>"
),
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.

0 comments on commit 605c509

Please sign in to comment.