From 1f5377f2119e23922c044b18005f21158e62173a Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy Date: Wed, 8 Nov 2023 13:58:58 +0100 Subject: [PATCH] Specify that `subscriptionCount` not conflating is a guarantee Addresses the new comment to #2871 --- kotlinx-coroutines-core/common/src/flow/SharedFlow.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kotlinx-coroutines-core/common/src/flow/SharedFlow.kt b/kotlinx-coroutines-core/common/src/flow/SharedFlow.kt index 1ded0a1750..588560e2c3 100644 --- a/kotlinx-coroutines-core/common/src/flow/SharedFlow.kt +++ b/kotlinx-coroutines-core/common/src/flow/SharedFlow.kt @@ -231,7 +231,11 @@ public interface MutableSharedFlow : SharedFlow, FlowCollector { * .launchIn(scope) // launch it * ``` * - * Implementation note: the resulting flow **does not** conflate subscription count. + * Usually, [StateFlow] conflates values, but [subscriptionCount] is not conflated. + * This is done so that any subscribers that need to be notified when subscribers appear do + * reliably observe it. With conflation, if a single subscriber appeared and immediately left, those + * collecting [subscriptionCount] could fail to notice it due to `0` immediately conflating the + * subscription count. */ public val subscriptionCount: StateFlow