Skip to content

Commit

Permalink
fix the bug regarding accessing flags using with context
Browse files Browse the repository at this point in the history
  • Loading branch information
vahidlazio committed Jun 19, 2024
1 parent 0848912 commit 8803aee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 9 additions & 7 deletions Confidence/src/main/java/com/spotify/confidence/Confidence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Confidence internal constructor(
private val parent: ConfidenceContextProvider? = null,
private val region: ConfidenceRegion = ConfidenceRegion.GLOBAL,
private val debugLogger: DebugLogger?
) : Contextual, EventSender {
) : ConfidenceAPI {
private val removedKeys = mutableListOf<String>()
private val contextMap = MutableStateFlow(initialContext)
private var currentFetchJob: Job? = null
Expand All @@ -50,11 +50,13 @@ class Confidence internal constructor(
private val eventProducers: MutableList<EventProducer> = mutableListOf()

init {
coroutineScope.launch {
contextChanges
.collect {
fetchAndActivate()
}
if (parent == null) {
coroutineScope.launch {
contextChanges
.collect {
fetchAndActivate()
}
}
}
}

Expand Down Expand Up @@ -144,7 +146,7 @@ class Confidence internal constructor(
it.getContext().filterKeys { key -> !removedKeys.contains(key) } + contextMap.value
} ?: contextMap.value

override fun withContext(context: Map<String, ConfidenceValue>): Confidence = Confidence(
override fun withContext(context: Map<String, ConfidenceValue>): ConfidenceAPI = Confidence(
clientSecret,
dispatcher,
eventSenderEngine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ interface Contextual : ConfidenceContextProvider {
fun putContext(context: Map<String, ConfidenceValue>)
fun putContext(key: String, value: ConfidenceValue)
fun removeContext(key: String)
}
}

interface ConfidenceAPI : Contextual, EventSender

0 comments on commit 8803aee

Please sign in to comment.