Skip to content
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!: Add ProviderState #46

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

feat!: Add ProviderState #46

wants to merge 11 commits into from

Conversation

fabriziodemaria
Copy link
Contributor

@fabriziodemaria fabriziodemaria commented Sep 4, 2024

This PR

  • Adds partial adherence to latest specifications related to ProviderState: spec docs
  • Early evaluation return if provider state is not "ready"

Breaking Changes

  • A backwards incompatible aspect of this change is that the initialize() implementation needs to throw in case of errors, rather than emitting the ERROR event. The latter is now responsibility of the SDK. This might apply to other parts of the integration as well (e.g. onContextChange)
  • This change in semantics is not enforced with code, and it might be easy for the Provider implementer to make mistakes when adopting this new version of the SDK (e.g. forget to remove ERROR emission from the Provider side)

Improvements

  • Introduce proper state machine framework for managing states/events

Signed-off-by: Fabrizio Demaria <[email protected]>
Signed-off-by: Fabrizio Demaria <[email protected]>
Signed-off-by: Fabrizio Demaria <[email protected]>
Comment on lines -98 to -104
let stateObserver = provider.observe().sink {
if $0 == .ready || $0 == .error {
continuation.resume()
holder.removeAll()
}
}
stateObserver.store(in: &holder)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a very good change

Signed-off-by: Fabrizio Demaria <[email protected]>
fix: setProvider sends Ready Event on success

Signed-off-by: Fabrizio Demaria <[email protected]>
Signed-off-by: Fabrizio Demaria <[email protected]>
Signed-off-by: Fabrizio Demaria <[email protected]>
Comment on lines -5 to -8
private let eventState: CurrentValueSubject<ProviderEvent, Never>
private let lastSentEvent = PassthroughSubject<ProviderEvent?, Never>()

convenience init() {
self.init(.notReady)
Copy link
Contributor Author

@fabriziodemaria fabriziodemaria Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EventHandler doesn't keep a "state" anymore, that is now responsibility of OpenFeatureAPI

Signed-off-by: Fabrizio Demaria <[email protected]>
@fabriziodemaria fabriziodemaria changed the title feat: Add ProviderState feat!: Add ProviderState Sep 6, 2024
Comment on lines +10 to +11
/// It is expected that the implementer is slow and blocking (e.g. network), the caller must deal with wrapping this into a background Task if necessary
func initialize(initialContext: EvaluationContext?) throws
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need docs like this for user-facing setContext and setContextAndWait, as well, so it's clear that the former can take time and should be called from the UI thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant