Skip to content

Commit be53823

Browse files
committed
fix race
1 parent 949a693 commit be53823

File tree

1 file changed

+4
-4
lines changed
  • features/dd-sdk-android-flags/src/main/kotlin/com/datadog/android/flags/internal

1 file changed

+4
-4
lines changed

features/dd-sdk-android-flags/src/main/kotlin/com/datadog/android/flags/internal/FlagsStateManager.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ internal class FlagsStateManager(
5656
* Registers a listener to receive state change notifications.
5757
*
5858
* The listener will immediately receive the current state, then be notified
59-
* of all future state changes.
59+
* of all future state changes. The current state is read atomically on the
60+
* same executor where all state updates occur, ensuring correct ordering.
6061
*
6162
* @param listener The listener to add.
6263
*/
6364
fun addListener(listener: FlagsStateListener) {
6465
subscription.addListener(listener)
6566

66-
// Emit current state to new listener
67-
val state = currentState
67+
// Emit current state to new listener - read inside executor for atomicity
6868
executorService.execute {
69-
listener.onStateChanged(state)
69+
listener.onStateChanged(currentState)
7070
}
7171
}
7272

0 commit comments

Comments
 (0)