Skip to content

Commit 5e870c1

Browse files
authored
Clarify behavior of produceIn. (#2976)
The previous wording said "thus resulting channel should be properly closed or cancelled," but it wasn't really clear what that meant -- whether the caller needed to close it or cancel it, or whether it would be properly closed by the implementation.
1 parent bf41f21 commit 5e870c1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ public fun <T> Flow<T>.broadcastIn(
217217
* Creates a [produce] coroutine that collects the given flow.
218218
*
219219
* This transformation is **stateful**, it launches a [produce] coroutine
220-
* that collects the given flow and thus resulting channel should be properly closed or cancelled.
220+
* that collects the given flow, and has the same behavior:
221+
*
222+
* * if collecting the flow throws, the channel will be closed with that exception
223+
* * if the [ReceiveChannel] is cancelled, the collection of the flow will be cancelled
224+
* * if collecting the flow completes normally, the [ReceiveChannel] will be closed normally
221225
*
222226
* A channel with [default][Channel.Factory.BUFFERED] buffer size is created.
223227
* Use [buffer] operator on the flow before calling `produceIn` to specify a value other than

0 commit comments

Comments
 (0)