Skip to content

feat: Update observeEvents() API #89

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

Merged
merged 2 commits into from
Jan 10, 2024
Merged

feat: Update observeEvents() API #89

merged 2 commits into from
Jan 10, 2024

Conversation

fabriziodemaria
Copy link
Contributor

@fabriziodemaria fabriziodemaria commented Jan 9, 2024

This PR

Update the OpenFeatureAPI.observeEvents() API:

  • It can be called by the Application layer before any provider is configured, and it will still receive events once a new provider is configured and emitting events
    • Thanks to this, we can now recommend setting up the observation before setProvider is called, thus ensuring no event from the configured provider is lost due to raciness between observer and setProvider

Usage example (from Application layer):

viewModelScope.launch {
    OpenFeatureAPI.observeEvents().collect {
        println(">> Event received: $it")
    }
}

viewModelScope.launch {
    OpenFeatureAPI.setProviderAndWait(
        ConfidenceFeatureProvider.create(
            app.applicationContext,
            clientSecret
        ),
        Dispatchers.IO,
        ctx
    )
}


var hooks: List<Hook<*>> = listOf()
private set

fun setProvider(provider: FeatureProvider, initialContext: EvaluationContext? = null) {
[email protected] = provider
providersFlow.tryEmit(provider)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: shall we close the flow on shutdown? Shall we emit something else on clearProvider?

Signed-off-by: Fabrizio Demaria <[email protected]>
@fabriziodemaria fabriziodemaria changed the title feat: Improved event observation API feat: Update observeEvents() API Jan 10, 2024
@fabriziodemaria fabriziodemaria marked this pull request as ready for review January 10, 2024 13:07
@fabriziodemaria fabriziodemaria merged commit 466115b into main Jan 10, 2024
@fabriziodemaria fabriziodemaria deleted the events branch January 10, 2024 13:31
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