Skip to content

Commit 06fd0c8

Browse files
authored
Update SharedFlow.kt
Coroutines and Flows are amazing I love them and many many thanks for them 🀩🀩🀩🀩 You guys in JetBrains rock 🀘🀘🀘 πŸš€πŸš€πŸš€ I have a small suggestion: According to this big discussion: Kotlin#2387 and a lot of confusion, including myself, default value of `extraBufferCapacity` should be 1 instead of 0 and I think this parameter also needs better explanation
1 parent 8a21e4b commit 06fd0c8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

β€Žkotlinx-coroutines-core/common/src/flow/SharedFlow.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ public interface MutableSharedFlow<T> : SharedFlow<T>, FlowCollector<T> {
253253
* @param replay the number of values replayed to new subscribers (cannot be negative, defaults to zero).
254254
* @param extraBufferCapacity the number of values buffered in addition to `replay`.
255255
* [emit][MutableSharedFlow.emit] does not suspend while there is a buffer space remaining (optional, cannot be negative, defaults to zero).
256+
* The buffer size (as a whole) impacts emitters. The exact consequence of a full buffer depends on onBufferOverflow,
257+
* but this buffer size can be used to control backpressure on emitters (slowing them down) or how we drop messages.
258+
* With a larger buffer, you can allow emitters to have bursts of emissions without slowing them down, like any regular buffer.
256259
* @param onBufferOverflow configures an [emit][MutableSharedFlow.emit] action on buffer overflow. Optional, defaults to
257260
* [suspending][BufferOverflow.SUSPEND] attempts to emit a value.
258261
* Values other than [BufferOverflow.SUSPEND] are supported only when `replay > 0` or `extraBufferCapacity > 0`.
@@ -263,7 +266,7 @@ public interface MutableSharedFlow<T> : SharedFlow<T>, FlowCollector<T> {
263266
@Suppress("FunctionName", "UNCHECKED_CAST")
264267
public fun <T> MutableSharedFlow(
265268
replay: Int = 0,
266-
extraBufferCapacity: Int = 0,
269+
extraBufferCapacity: Int = 1,
267270
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
268271
): MutableSharedFlow<T> {
269272
require(replay >= 0) { "replay cannot be negative, but was $replay" }

0 commit comments

Comments
Β (0)