Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ public void example(){

// configure a provider
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProviderAndWait(new InMemoryProvider(myFlags));
try {
api.setProviderAndWait(new InMemoryProvider(myFlags));
} catch (Exception e) {
// handle initialization failure
e.printStackTrace();
}

// create a client
Client client = api.getClient();
Expand Down Expand Up @@ -149,7 +154,12 @@ To register a provider in a blocking manner to ensure it is ready before further

```java
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProviderAndWait(new MyProvider());
try {
api.setProviderAndWait(new MyProvider());
} catch (Exception e) {
// handle initialization failure
e.printStackTrace();
}
```

#### Asynchronous
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ public void setProvider(String domain, FeatureProvider provider) {
}

/**
* Set the default provider and wait for initialization to finish.
* Sets the default provider and waits for its initialization to complete.
*
* <p>Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown.
* It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully.
*
* @param provider the {@link FeatureProvider} to set as the default.
* @throws OpenFeatureError if the provider fails during initialization.
*/
public void setProviderAndWait(FeatureProvider provider) throws OpenFeatureError {
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
Expand All @@ -224,8 +230,12 @@ public void setProviderAndWait(FeatureProvider provider) throws OpenFeatureError
/**
* Add a provider for a domain and wait for initialization to finish.
*
* <p>Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown.
* It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully.
*
* @param domain The domain to bind the provider to.
* @param provider The provider to set.
* @throws OpenFeatureError if the provider fails during initialization.
*/
public void setProviderAndWait(String domain, FeatureProvider provider) throws OpenFeatureError {
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
Expand Down
Loading