@@ -55,12 +55,12 @@ dependencies {
55
55
### Usage
56
56
57
57
``` kotlin
58
- // configure a provider and get client
59
58
coroutineScope.launch(Dispatchers .IO ) {
59
+ // configure a provider, wait for it to complete its initialization tasks
60
60
OpenFeatureAPI .setProviderAndWait(customProvider)
61
61
val client = OpenFeatureAPI .getClient()
62
62
63
- // get a bool flag value
63
+ // get a bool flag value
64
64
client.getBooleanValue(" boolFlag" , default = false )
65
65
}
66
66
```
@@ -74,7 +74,7 @@ coroutineScope.launch(Dispatchers.IO) {
74
74
| ✅ | [ Hooks] ( #hooks ) | Add functionality to various stages of the flag evaluation life-cycle. |
75
75
| ❌ | Logging | Integrate with popular logging packages. |
76
76
| ❌ | Named clients | Utilize multiple providers in a single application. |
77
- | ⚠ ️ | [ Eventing] ( #eventing ) | React to state changes in the provider or flag management system. |
77
+ | ✅ ️ | [ Eventing] ( #eventing ) | React to state changes in the provider or flag management system. |
78
78
| ✅ | [ Shutdown] ( #shutdown ) | Gracefully clean up a provider during application shutdown. |
79
79
| ⚠️ | [ Extending] ( #extending ) | Extend OpenFeature with custom providers and hooks. |
80
80
@@ -89,9 +89,11 @@ If the provider you're looking for hasn't been created yet, see the [develop a p
89
89
Once you've added a provider as a dependency, it can be registered with OpenFeature like this:
90
90
91
91
``` kotlin
92
- OpenFeatureAPI .setProvider (MyProvider ())
92
+ OpenFeatureAPI .setProviderAndWait (MyProvider ())
93
93
```
94
94
95
+ _ (Asynchronous API that doesn't wait is also available)_
96
+
95
97
96
98
### Targeting
97
99
@@ -137,13 +139,28 @@ Some providers support additional events, such as `PROVIDER_CONFIGURATION_CHANGE
137
139
138
140
Please refer to the documentation of the provider you're using to see what events are supported.
139
141
142
+ Example usage:
140
143
``` kotlin
141
- OpenFeatureAPI .observeEvents<OpenFeatureEvents .ProviderReady >()
142
- ?.collect {
143
- // do something once the provider is ready
144
- }
144
+ viewModelScope.launch {
145
+ OpenFeatureAPI .observe<OpenFeatureEvents .ProviderReady >().collect {
146
+ println (" >> ProviderReady event received" )
147
+ }
148
+ }
149
+
150
+ viewModelScope.launch {
151
+ OpenFeatureAPI .setProviderAndWait(
152
+ ConfidenceFeatureProvider .create(
153
+ applicationContext,
154
+ clientSecret
155
+ ),
156
+ Dispatchers .IO ,
157
+ myEvaluationContext
158
+ )
159
+ }
145
160
```
146
161
162
+ <!-- (It's only possible to observe events from the global `OpenFeatureAPI`, until multiple providers are supported) -->
163
+
147
164
### Shutdown
148
165
149
166
The OpenFeature API provides a close function to perform a cleanup of the registered provider.
@@ -210,6 +227,13 @@ class NewProvider(override val hooks: List<Hook<*>>, override val metadata: Meta
210
227
// add necessary changes on context change
211
228
}
212
229
230
+ override fun observe (): Flow <OpenFeatureEvents > {
231
+ // return a `Flow` of the Events
232
+ }
233
+
234
+ override fun getProviderStatus (): OpenFeatureEvents {
235
+ // return the event representative of the current Provider Status
236
+ }
213
237
}
214
238
```
215
239
0 commit comments