Skip to content

Commit 856a66b

Browse files
docs: Update docs with setProviderAndWait
Signed-off-by: Fabrizio Demaria <[email protected]>
1 parent bf5057e commit 856a66b

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

README.md

+13-16
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,18 @@ and in the target dependencies section add:
7676
```swift
7777
import OpenFeature
7878

79-
// Configure your custom `FeatureProvider` and pass it to OpenFeatureAPI
80-
let customProvider = MyCustomProvider()
81-
OpenFeatureAPI.shared.setProvider(provider: customProvider)
82-
83-
// Configure your evaluation context and pass it to OpenFeatureAPI
84-
let ctx = MutableContext(
85-
targetingKey: userId,
86-
structure: MutableStructure(attributes: ["product": Value.string(productId)]))
87-
OpenFeatureAPI.shared.setEvaluationContext(evaluationContext: ctx)
88-
89-
// Get client from OpenFeatureAPI and evaluate your flags
90-
let client = OpenFeatureAPI.shared.getClient()
91-
let flagValue = client.getBooleanValue(key: "boolFlag", defaultValue: false)
79+
Task {
80+
let provider = CustomProvider()
81+
// configure a provider, wait for it to complete its initialization tasks
82+
await OpenFeatureAPI.shared.setProviderAndWait(provider: provider)
83+
84+
// get a bool flag value
85+
let client = OpenFeatureAPI.shared.getClient()
86+
let flagValue = client.getBooleanValue(key: "boolFlag", defaultValue: false)
87+
...
88+
}
9289
```
9390

94-
Setting a new provider or setting a new evaluation context might trigger asynchronous operations (e.g. fetching flag evaluations from the backend and store them in a local cache). It's advised to not interact with the OpenFeature client until the `ProviderReady` event has been sent (see [Eventing](#eventing) below).
95-
9691
## 🌟 Features
9792

9893

@@ -118,9 +113,11 @@ If the provider you're looking for hasn't been created yet, see the [develop a p
118113
Once you've added a provider as a dependency, it can be registered with OpenFeature like this:
119114

120115
```swift
121-
OpenFeatureAPI.shared.setEvaluationContext(evaluationContext: ctx)
116+
await OpenFeatureAPI.shared.setProviderAndWait(provider: MyProvider())
122117
```
123118

119+
> Asynchronous API that doesn't wait is also available
120+
124121
### Targeting
125122

126123
Sometimes, the value of a flag must consider some dynamic criteria about the application or user, such as the user's location, IP, email address, or the server's location.

0 commit comments

Comments
 (0)