Skip to content

Commit 7d9467c

Browse files
authored
Fix receiveAsFlow not mentioning the prompt cancellation guarantee (#4366)
Fixes #4337
1 parent d3f1f23 commit 7d9467c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: kotlinx-coroutines-core/common/src/flow/Channels.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ private suspend fun <T> FlowCollector<T>.emitAllImpl(channel: ReceiveChannel<T>,
5151
* - Flow collectors are cancelled when the original channel is [closed][SendChannel.close] with an exception.
5252
* - Flow collectors complete normally when the original channel is [closed][SendChannel.close] normally.
5353
* - Failure or cancellation of the flow collector does not affect the channel.
54+
* However, if a flow collector gets cancelled after receiving an element from the channel but before starting
55+
* to process it, the element will be lost, and the `onUndeliveredElement` callback of the [Channel],
56+
* if provided on channel construction, will be invoked.
57+
* See [Channel.receive] for details of the effect of the prompt cancellation guarantee on element delivery.
5458
*
5559
* ### Operator fusion
5660
*
@@ -71,7 +75,8 @@ public fun <T> ReceiveChannel<T>.receiveAsFlow(): Flow<T> = ChannelAsFlow(this,
7175
*
7276
* - Flow collector is cancelled when the original channel is [closed][SendChannel.close] with an exception.
7377
* - Flow collector completes normally when the original channel is [closed][SendChannel.close] normally.
74-
* - If the flow collector fails with an exception, the source channel is [cancelled][ReceiveChannel.cancel].
78+
* - If the flow collector fails with an exception (for example, by getting cancelled),
79+
* the source channel is [cancelled][ReceiveChannel.cancel].
7580
*
7681
* ### Operator fusion
7782
*

0 commit comments

Comments
 (0)