Skip to content

Commit dc95311

Browse files
lowasserpablobaxter
authored andcommitted
Clarify behavior of produceIn. (Kotlin#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 608fed6 commit dc95311

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
@@ -182,7 +182,11 @@ public fun <T> BroadcastChannel<T>.asFlow(): Flow<T> = flow {
182182
* Creates a [produce] coroutine that collects the given flow.
183183
*
184184
* This transformation is **stateful**, it launches a [produce] coroutine
185-
* that collects the given flow and thus resulting channel should be properly closed or cancelled.
185+
* that collects the given flow, and has the same behavior:
186+
*
187+
* * if collecting the flow throws, the channel will be closed with that exception
188+
* * if the [ReceiveChannel] is cancelled, the collection of the flow will be cancelled
189+
* * if collecting the flow completes normally, the [ReceiveChannel] will be closed normally
186190
*
187191
* A channel with [default][Channel.Factory.BUFFERED] buffer size is created.
188192
* Use [buffer] operator on the flow before calling `produceIn` to specify a value other than

0 commit comments

Comments
 (0)