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

updated to use correct comparison for distinctUntilChanged #97

Merged
merged 5 commits into from
Nov 12, 2024

Conversation

chriswk
Copy link
Member

@chriswk chriswk commented Nov 12, 2024

Make sure we fetch when we setContextAsync, but also make sure we don't fetch twice when we setContext (sync method).

Fix #96

@chriswk chriswk self-assigned this Nov 12, 2024
@chriswk chriswk linked an issue Nov 12, 2024 that may be closed by this pull request
)
} else if (inFlightCall != null && !inFlightCall.isCanceled()) {
} else if (inFlightCall != null && !inFlightCall.isCanceled() && !inFlightCall.isExecuted()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not cancel completed requests


fun getFeaturesReceivedFlow() = featuresReceivedFlow.asSharedFlow()

fun startWatchingContext() {
unleashScope.launch {
unleashContext.distinctUntilChanged { old, new -> old != new }.collect {
Copy link
Contributor

Choose a reason for hiding this comment

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

https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/

Values in state flow are conflated using Any.equals comparison in a similar way to distinctUntilChanged operator. It is used to conflate incoming updates to value in MutableStateFlow and to suppress emission of the values to collectors when new value is equal to the previously emitted one. State flow behavior with classes that violate the contract for Any.equals is unspecified.

) : Closeable {
companion object {
private const val TAG = "UnleashFetcher"
}

private var contextForLastFetch: UnleashContext? = null
Copy link
Contributor

Choose a reason for hiding this comment

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

Hold the last fetched so we can ignore refreshing toggles when context has change due to a sync setContext which avoids 2 fetch calls for the same context

Copy link
Contributor

@gastonfournier gastonfournier left a comment

Choose a reason for hiding this comment

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

Good team work!

@chriswk chriswk merged commit cc271b9 into main Nov 12, 2024
1 of 2 checks passed
@chriswk chriswk deleted the 96-refreshtoggles-is-not-called-after-setcontextasync branch November 12, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

refreshToggles() is not called after setContextAsync()
2 participants