Skip to content

Commit 865c229

Browse files
authored
Additional docs on unbuffered shared flow (#2346)
1 parent c35ce7e commit 865c229

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ import kotlin.native.concurrent.*
6868
* the `onBufferOverflow` parameter, which is equal to one of the entries of the [BufferOverflow] enum. When a strategy other
6969
* than [SUSPENDED][BufferOverflow.SUSPEND] is configured, emissions to the shared flow never suspend.
7070
*
71+
* ### Unbuffered shared flow
72+
*
73+
* A default implementation of a shared flow that is created with `MutableSharedFlow()` constructor function
74+
* without parameters has no replay cache nor additional buffer.
75+
* [emit][MutableSharedFlow.emit] call to such a shared flow suspends until all subscribers receive the emitted value
76+
* and returns immediately if there are no subscribers.
77+
* Thus, [tryEmit][MutableSharedFlow.tryEmit] call succeeds and returns `true` only if
78+
* there are no subscribers (in which case the emitted value is immediately lost).
79+
*
7180
* ### SharedFlow vs BroadcastChannel
7281
*
7382
* Conceptually shared flow is similar to [BroadcastChannel][BroadcastChannel]

0 commit comments

Comments
 (0)