From 8803aee4c65a45225460ff3333fbe3f6a9057b4a Mon Sep 17 00:00:00 2001 From: vahid torkaman Date: Wed, 19 Jun 2024 17:30:26 +0200 Subject: [PATCH] fix the bug regarding accessing flags using with context --- .../java/com/spotify/confidence/Confidence.kt | 16 +++++++++------- .../com/spotify/confidence/ConfidenceContext.kt | 4 +++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Confidence/src/main/java/com/spotify/confidence/Confidence.kt b/Confidence/src/main/java/com/spotify/confidence/Confidence.kt index 1fbf6cfd..6eb8dab5 100644 --- a/Confidence/src/main/java/com/spotify/confidence/Confidence.kt +++ b/Confidence/src/main/java/com/spotify/confidence/Confidence.kt @@ -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() private val contextMap = MutableStateFlow(initialContext) private var currentFetchJob: Job? = null @@ -50,11 +50,13 @@ class Confidence internal constructor( private val eventProducers: MutableList = mutableListOf() init { - coroutineScope.launch { - contextChanges - .collect { - fetchAndActivate() - } + if (parent == null) { + coroutineScope.launch { + contextChanges + .collect { + fetchAndActivate() + } + } } } @@ -144,7 +146,7 @@ class Confidence internal constructor( it.getContext().filterKeys { key -> !removedKeys.contains(key) } + contextMap.value } ?: contextMap.value - override fun withContext(context: Map): Confidence = Confidence( + override fun withContext(context: Map): ConfidenceAPI = Confidence( clientSecret, dispatcher, eventSenderEngine, diff --git a/Confidence/src/main/java/com/spotify/confidence/ConfidenceContext.kt b/Confidence/src/main/java/com/spotify/confidence/ConfidenceContext.kt index 950a0239..4fe50e39 100644 --- a/Confidence/src/main/java/com/spotify/confidence/ConfidenceContext.kt +++ b/Confidence/src/main/java/com/spotify/confidence/ConfidenceContext.kt @@ -12,4 +12,6 @@ interface Contextual : ConfidenceContextProvider { fun putContext(context: Map) fun putContext(key: String, value: ConfidenceValue) fun removeContext(key: String) -} \ No newline at end of file +} + +interface ConfidenceAPI : Contextual, EventSender \ No newline at end of file