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

docs: Spec putContext / track(ConfidenceContextProducer) #175

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

fabriziodemaria
Copy link
Member

@fabriziodemaria fabriziodemaria commented Nov 11, 2024

Observation 1

From the DemoApp:

@StateObject private var lifecycleObserver: ConfidenceContextProducer = ConfidenceAppLifecycleProducer()
...
let confidence = Confidence.Builder(...).build()
confidence.track(producer: lifecycleObserver) // triggers fetchAndActivate
...
try await confidence.fetchAndActivate() // the app calls fetchAndActivate

The ideal situation would be to have a single fetchAndActivate call, and the ability to await an async function to make sure the flags are fresh and ready in the cache. However, our current API portfolio doesn't seem to allow for both of those things together.

Observation 2

Code snippet here.

Today it's impossible to have a setup where the context is changed and the UI showing a loading indicator until the resolve is complete, while at the same time having a single fetchAndActivate call for each context change.

Possible improvements

  • Confidence builder accept a list of ContextProducers, and applies the context from them for the first time without calling fetchAndActivate
  • putContext is made async: users can wait for the new flags to be ready before reading values (this is probably harder to achieve with the ContextProducer solution)

README.md Outdated Show resolved Hide resolved
Co-authored-by: Nicklas Lundin <[email protected]>
nicklasl
nicklasl previously approved these changes Nov 12, 2024
@fabriziodemaria fabriziodemaria removed their assignment Nov 12, 2024

In both cases above, any context change triggers a new asynchronous `fetchAndActivate` and the flags in the
local cache are re-evaluated remotely according to the new context: until this background operation is complete,
flag values are returned to the application according to the old context's evaluation, and with `resolveReason = .stale`.
Copy link
Member Author

@fabriziodemaria fabriziodemaria Nov 12, 2024

Choose a reason for hiding this comment

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

Here, I would add the following to the Spec:

putContext is an await-able function, which returns when the flag cache is ready and reflects the newly configured context. When using ConfidenceContextProducer, the context can change more dynamically and stale value are to be expected.

@fabriziodemaria fabriziodemaria changed the title docs: Spec the behaviour of putContext docs: Spec putContext / track(ConfidenceContextProducer) Nov 12, 2024
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.

2 participants