Skip to content

Commit 8b32c4e

Browse files
authored
Fix an explanation of flowOn Operator (#4402)
1 parent 1a82e0c commit 8b32c4e

File tree

1 file changed

+8
-6
lines changed
  • kotlinx-coroutines-core/common/src/flow/operators

1 file changed

+8
-6
lines changed

kotlinx-coroutines-core/common/src/flow/operators/Context.kt

+8-6
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,14 @@ public fun <T> Flow<T>.conflate(): Flow<T> = buffer(CONFLATED)
209209
*
210210
* For more explanation of context preservation please refer to [Flow] documentation.
211211
*
212-
* This operator retains a _sequential_ nature of flow if changing the context does not call for changing
213-
* the [dispatcher][CoroutineDispatcher]. Otherwise, if changing dispatcher is required, it collects
214-
* flow emissions in one coroutine that is run using a specified [context] and emits them from another coroutines
215-
* with the original collector's context using a channel with a [default][Channel.BUFFERED] buffer size
216-
* between two coroutines similarly to [buffer] operator, unless [buffer] operator is explicitly called
217-
* before or after `flowOn`, which requests buffering behavior and specifies channel size.
212+
* This operator retains the _sequential_ nature of the flow as long as the context change does not involve
213+
* changing the [dispatcher][CoroutineDispatcher].
214+
* However, if the dispatcher is changed, the flow's emissions are performed in a coroutine running with the
215+
* specified [context], and the values are collected in another coroutine using the original collector's context.
216+
* In this case, a channel with a [default][Channel.BUFFERED] buffer size is used internally between the two
217+
* coroutines, similar to the behavior of the [buffer] operator.
218+
* If a [buffer] operator is explicitly called before or after `flowOn`, it overrides the default buffering behavior
219+
* and determines the channel size explicitly.
218220
*
219221
* Note, that flows operating across different dispatchers might lose some in-flight elements when cancelled.
220222
* In particular, this operator ensures that downstream flow does not resume on cancellation even if the element

0 commit comments

Comments
 (0)