open-feature / js-sdk

JavaScript SDK for OpenFeature
https://openfeature.dev
Apache License 2.0
120 stars 31 forks source link

[FEATURE] Update setProvider to be async and remove setProviderAndWait #695

Open beeme1mr opened 7 months ago

beeme1mr commented 7 months ago

Requirements

Overview

When setProvider was first introduced, OpenFeature didn't have support for provider initialization. It was expected that a provider was initialized prior to registering it with OpenFeature. Since then, OpenFeature has added support for initialization so that the SDK could have an awareness of the provider lifecycle and is able to emit events that developers can subscribe to. Unfortunately, this meant that a provider may not be available immediately after registration. To overcome this, developers could wait for the provider ready event to fire before performing flag evaluations. A method called setProviderAndWait was also added that returned a promise. The promise resolves when the provider is ready or is rejected if there's an error during initialization.

We've received feedback that setProviderAndWait behaves the way people expect setProvider to work. Also, setProviderAndWait is not a good name in JavaScript because it does not block a thread as the name implies. For these reasons, setProvider should be updated to behave like setProviderAndWait and setProviderAndWait should be removed. This will be a breaking change that will require a v2.0.0 of the server SDK.

Requirements

toddbaert commented 7 months ago

Worth mentioning that this is how it works in the .NET SDK as well, since this change. This is relevant because .NET features basically the same async/await semantics as TS/JS.