Skip to content

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
    )
}

Signed-off-by: Fabrizio Demaria <fdema@spotify.com>

fun setProvider(provider: FeatureProvider, initialContext: EvaluationContext? = null) {
this@OpenFeatureAPI.provider = 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 <fdema@spotify.com>
@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.

3 participants