From 5f044c1bd35ae3dbe17b6b93ea8453914fadc8de Mon Sep 17 00:00:00 2001 From: Louis Wasserman Date: Mon, 11 Oct 2021 12:15:12 -0700 Subject: [PATCH] Clarify behavior of produceIn. 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. --- kotlinx-coroutines-core/common/src/flow/Channels.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kotlinx-coroutines-core/common/src/flow/Channels.kt b/kotlinx-coroutines-core/common/src/flow/Channels.kt index 382953efcb..9c6051d36d 100644 --- a/kotlinx-coroutines-core/common/src/flow/Channels.kt +++ b/kotlinx-coroutines-core/common/src/flow/Channels.kt @@ -217,7 +217,11 @@ public fun Flow.broadcastIn( * Creates a [produce] coroutine that collects the given flow. * * This transformation is **stateful**, it launches a [produce] coroutine - * that collects the given flow and thus resulting channel should be properly closed or cancelled. + * that collects the given flow, and has the same behavior: + * + * * if collecting the flow throws, the channel will be closed with that exception + * * if the [ReceiveChannel] is cancelled, the collection of the flow will be cancelled + * * if collecting the flow completes normally, the [ReceiveChannel] will be closed normally * * A channel with [default][Channel.Factory.BUFFERED] buffer size is created. * Use [buffer] operator on the flow before calling `produceIn` to specify a value other than