Skip to content

Commit cd94f09

Browse files
committed
Fix an explanation of flowOn Operator
1 parent 96de301 commit cd94f09

File tree

1 file changed

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

1 file changed

+9
-6
lines changed

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,15 @@ 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
213+
* does not involve changing the [dispatcher][CoroutineDispatcher].
214+
* However, if the dispatcher is changed, the flow's emissions are performed in a coroutine
215+
* running with the specified [context], and the values are collected in another coroutine
216+
* using the original collector's context.
217+
* In this case, a channel with a [default][Channel.BUFFERED] buffer size is used internally
218+
* between the two coroutines, similar to the behavior of the [buffer] operator.
219+
* If a [buffer] operator is explicitly called before or after `flowOn`, it overrides the default
220+
* buffering behavior and determines the channel size explicitly.
218221
*
219222
* Note, that flows operating across different dispatchers might lose some in-flight elements when cancelled.
220223
* In particular, this operator ensures that downstream flow does not resume on cancellation even if the element

0 commit comments

Comments
 (0)