js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

[FEATURE] Update setProvider to be async and remove setProviderAndWait

Open beeme1mr opened this issue 2 years ago • 1 comments

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

  • setProvider returns a promise that's resolved when the provider is ready or is rejected if the provider fails during initialization.
  • Remove setProviderAndWait
  • Update the documentation in the readme

beeme1mr avatar Nov 28 '23 17:11 beeme1mr

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.

toddbaert avatar Nov 28 '23 17:11 toddbaert