Skip to content

Commit 461473e

Browse files
committed
Clarify capacity parameter in broadcast builders
Addresses #815
1 parent b0dfdcd commit 461473e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

common/kotlinx-coroutines-core-common/src/channels/Broadcast.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import kotlin.coroutines.*
1313
/**
1414
* Broadcasts all elements of the channel.
1515
*
16-
* @param capacity capacity of the channel's buffer (1 by default).
16+
* The kind of the resulting channel depends on the specified [capacity] parameter:
17+
* when `capacity` is positive (1 by default), but less than [UNLIMITED] -- uses `ArrayBroadcastChannel` with a buffer of given capacity,
18+
* when `capacity` is [CONFLATED] -- uses [ConflatedBroadcastChannel] that conflates back-to-back sends;
19+
* Note that resulting channel behaves like [ConflatedBroadcastChannel] but is not an instance of [ConflatedBroadcastChannel].
20+
* otherwise -- throws [IllegalArgumentException].
21+
*
1722
* @param start coroutine start option. The default value is [CoroutineStart.LAZY].
1823
*/
1924
fun <E> ReceiveChannel<E>.broadcast(
@@ -45,8 +50,9 @@ fun <E> ReceiveChannel<E>.broadcast(
4550
* the resulting channel becomes _failed_, so that any attempt to receive from such a channel throws exception.
4651
*
4752
* The kind of the resulting channel depends on the specified [capacity] parameter:
48-
* * when `capacity` positive (1 by default), but less than [UNLIMITED] -- uses `ArrayBroadcastChannel` with a buffer of given capacity,
53+
* * when `capacity` is positive (1 by default), but less than [UNLIMITED] -- uses `ArrayBroadcastChannel` with a buffer of given capacity,
4954
* * when `capacity` is [CONFLATED] -- uses [ConflatedBroadcastChannel] that conflates back-to-back sends;
55+
* Note that resulting channel behaves like [ConflatedBroadcastChannel] but is not an instance of [ConflatedBroadcastChannel].
5056
* * otherwise -- throws [IllegalArgumentException].
5157
*
5258
* **Note:** By default, the coroutine does not start until the first subscriber appears via [BroadcastChannel.openSubscription]

common/kotlinx-coroutines-core-common/src/channels/BroadcastChannel.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
@file:Suppress("FunctionName")
6+
57
package kotlinx.coroutines.channels
68

79
import kotlinx.coroutines.*
810
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED
911
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
10-
import kotlinx.coroutines.internal.*
1112

1213
/**
1314
* Broadcast channel is a non-blocking primitive for communication between the sender and multiple receivers

0 commit comments

Comments
 (0)