Skip to content

Commit 3dd48ac

Browse files
authored
Specify that subscriptionCount not conflating is a guarantee (#3934)
Addresses the new comment to #2871
1 parent e69bc2c commit 3dd48ac

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

kotlinx-coroutines-core/common/src/flow/SharedFlow.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,11 @@ public interface MutableSharedFlow<T> : SharedFlow<T>, FlowCollector<T> {
231231
* .launchIn(scope) // launch it
232232
* ```
233233
*
234-
* Implementation note: the resulting flow **does not** conflate subscription count.
234+
* Usually, [StateFlow] conflates values, but [subscriptionCount] is not conflated.
235+
* This is done so that any subscribers that need to be notified when subscribers appear do
236+
* reliably observe it. With conflation, if a single subscriber appeared and immediately left, those
237+
* collecting [subscriptionCount] could fail to notice it due to `0` immediately conflating the
238+
* subscription count.
235239
*/
236240
public val subscriptionCount: StateFlow<Int>
237241

0 commit comments

Comments
 (0)