-
Notifications
You must be signed in to change notification settings - Fork 43
docs: document setProviderAndWait in README #610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
toddbaert
merged 5 commits into
open-feature:main
from
code4Y:readme-include-setProviderAndWait
Sep 14, 2023
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
180d214
Update setProviderAndWait in README.md
code4Y a9b2a8c
Update Provider and Named clients README.md
code4Y 8fe6a5f
Merge branch 'main' into readme-include-setProviderAndWait
toddbaert bd478a6
Merge branch 'main' into readme-include-setProviderAndWait
toddbaert 78534c6
Merge branch 'main' into readme-include-setProviderAndWait
toddbaert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,7 +104,7 @@ public void example(){ | |
|
||
// configure a provider | ||
OpenFeatureAPI api = OpenFeatureAPI.getInstance(); | ||
api.setProvider(new InMemoryProvider(myFlags)); | ||
api.setProviderAndWait(new InMemoryProvider(myFlags)); | ||
|
||
// create a client | ||
Client client = api.getClient(); | ||
|
@@ -139,12 +139,28 @@ See [here](https://javadoc.io/doc/dev.openfeature/sdk/latest/) for the Javadocs. | |
Look [here](https://openfeature.dev/ecosystem?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Provider&instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=Java) for a complete list of available providers. | ||
If the provider you're looking for hasn't been created yet, see the [develop a provider](#develop-a-provider) section to learn how to build it yourself. | ||
|
||
Once you've added a provider as a dependency, it can be registered with OpenFeature like this: | ||
Once you've added a provider as a dependency, you can register it with OpenFeature in either an asynchronous or synchronous manner. Below are examples of how to set providers using both methods: | ||
|
||
#### Asynchronous Provider Registration | ||
To register a provider asynchronously, ensuring it is initialized before further actions are taken, you can use the `setProviderAndWait` method as shown in the following example: | ||
|
||
```java | ||
OpenFeatureAPI.getInstance().setProvider(new MyProvider()); | ||
OpenFeatureAPI api = OpenFeatureAPI.getInstance(); | ||
api.setProviderAndWait(new MyProvider()); | ||
``` | ||
|
||
This method is appropriate when you need to wait for the provider's initialization to complete before proceeding. | ||
|
||
#### Synchronous Provider Registration | ||
For synchronous provider registration, where you set the provider without waiting for initialization, you can use the `setProvider` method directly: | ||
|
||
```java | ||
OpenFeatureAPI api = OpenFeatureAPI.getInstance(); | ||
api.setProvider(new MyProvider()); | ||
``` | ||
|
||
This is a straightforward synchronous operation, suitable when you don't need to wait for the provider to initialize before continuing. | ||
|
||
In some situations, it may be beneficial to register multiple providers in the same application. | ||
This is possible using [named clients](#named-clients), which is covered in more details below. | ||
|
||
|
@@ -211,19 +227,41 @@ Clients can be given a name. | |
A name is a logical identifier which can be used to associate clients with a particular provider. | ||
If a name has no associated provider, the global provider is used. | ||
|
||
#### Asynchronous Named Provider Configuration | ||
|
||
To register providers asynchronously, ensuring they are initialized before further actions are taken, you can use the `setProviderAndWait` method as shown below: | ||
|
||
```java | ||
FeatureProvider scopedProvider = new MyProvider(); | ||
|
||
// registering the default provider | ||
// registering the default provider asynchronously | ||
OpenFeatureAPI.getInstance().setProviderAndWait(LocalProvider()); | ||
// registering a named provider asynchronously | ||
OpenFeatureAPI.getInstance().setProviderAndWait("clientForCache", new CachedProvider()); | ||
|
||
// a client backed by the default provider | ||
Client clientDefault = OpenFeatureAPI.getInstance().getClient(); | ||
// a client backed by CachedProvider | ||
Client clientNamed = OpenFeatureAPI.getInstance().getClient("clientForCache"); | ||
``` | ||
|
||
#### Synchronous Named Provider Configuration | ||
|
||
For synchronous provider registration, where you set the provider without waiting for initialization, you can use the `setProvider` method directly, as shown in the following example: | ||
|
||
```java | ||
FeatureProvider scopedProvider = new MyProvider(); | ||
|
||
// registering the default provider synchronously | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need to repeat yourself here. Just mention that named providers can be set in a blocking/non-blocking way, and then link to the previous doc you wrote above. |
||
OpenFeatureAPI.getInstance().setProvider(LocalProvider()); | ||
// registering a named provider | ||
// registering a named provider synchronously | ||
OpenFeatureAPI.getInstance().setProvider("clientForCache", new CachedProvider()); | ||
|
||
// a client backed by default provider | ||
Client clientDefault = OpenFeatureAPI.getInstance().getClient(); | ||
// a client backed by CachedProvider | ||
Client clientNamed = OpenFeatureAPI.getInstance().getClient("clientForCache"); | ||
``` | ||
``` | ||
|
||
### Eventing | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.