-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat!: Spec v0.8 adherence #46
base: main
Are you sure you want to change the base?
Conversation
203e8da
to
40d0812
Compare
cabfae2
to
533f1ab
Compare
16499c7
to
78a30e5
Compare
ba7c072
to
ac15098
Compare
Signed-off-by: Fabrizio Demaria <[email protected]>
Signed-off-by: Fabrizio Demaria <[email protected]>
76cd647
to
eacbb12
Compare
Signed-off-by: Fabrizio Demaria <[email protected]>
eacbb12
to
f1fe08f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @fabriziodemaria, the change looks good from what I can tell (limited experience with Swift). Since this is a breaking change, it may be a good time to update the afterAll
stage in the hooks to comply with a recent update to the spec.
https://openfeature.dev/specification/sections/hooks#requirement-438
This will make it easy to support more sophisticated telemetry use cases.
Co-authored-by: Michael Beemer <[email protected]> Signed-off-by: Fabrizio Demaria <[email protected]>
Co-authored-by: Michael Beemer <[email protected]> Signed-off-by: Fabrizio Demaria <[email protected]>
Co-authored-by: Michael Beemer <[email protected]> Signed-off-by: Fabrizio Demaria <[email protected]>
Signed-off-by: Fabrizio Demaria <[email protected]>
5da87b7
to
2c7886b
Compare
Signed-off-by: Fabrizio Demaria <[email protected]>
Signed-off-by: Fabrizio Demaria <[email protected]>
17eeb61
to
81c9fa2
Compare
/** | ||
Set provider and calls its `initialize` in a background thread. | ||
Readiness can be determined from `getState` or listening for `ready` event. | ||
*/ | ||
public func setProvider(provider: FeatureProvider, initialContext: EvaluationContext?) { | ||
queue.async { | ||
Task { | ||
await self.setProviderInternal(provider: provider, initialContext: initialContext) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One limitation that came up during manual testing on a sample app
Now the OpenFeature SDK only offers two APIs to set a Provider, and both require await
from the Application: await for an async function (i.e. setProviderAndAwait) or await for a .ready
event.
If a Provider offers local-resolve or cached flags data, it would be useful to offer a non-await
(i.e. synchronous) function to set the Provider and have it "ready" right away: synchronous functions are easier to integrate in the Application (especially at startup, when latency is critical).
One possibility could be to make setProvider
blocking until initialize
(which is called inside "setProviderInternal") is finished:
public func setProvider(provider: FeatureProvider, initialContext: EvaluationContext?) {
let semaphore = DispatchSemaphore(value: 0)
let _ = queue.sync {
Task {
await self.setProviderInternal(provider: provider, initialContext: initialContext)
semaphore.signal()
}
}
semaphore.wait()
}
A more robust solution would be to have Providers implement a non-async initialize
for the synchronous case, and an async initialize
for when network operations are required.
This will require a bit more thinking, and I suggest we refrain from merging until we have a more clear idea on how we want to tackle this
Spec v0.8 adherence
Ready
,Error
orFatal
are emitted by the SDK and are not expected by the Provider implementations.initialize
andonContextChange
protocols throwing, allowing for the OpenFeatureAPI layer to detect cases whereError
events should be emittedinitialize
andonContextChange
protocols async for an easier Provider implementation (in most cases)Missing parts
It's possible that the on context changed function is invoked simultaneously or in quick succession; in this case the SDK will only run the PROVIDER_CONTEXT_CHANGED handlers after all reentrant invocations have terminated, and the last to terminate was successful (terminated normally)
Changes unrelated to Spec v0.8
setEvaluationContextAndWait
to provide the same better ergonomics thatsetProviderAndWait
already offersafterAll
hook to adhere to latest conventionsNotes on backwards compatibility
initialize()
implementation needs to throw in case of errors, rather than emitting theERROR
event. The latter is now responsibility of the SDK. This is also valid foronContextChange
.ERROR
emission from the Provider side)Example Adoption
The Confidence OpenFeature Provider adopting this version of the SDK is in the works here: spotify/confidence-sdk-swift#184