You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: kotlinx-coroutines-core/common/src/flow/operators/Context.kt
+14-2
Original file line number
Diff line number
Diff line change
@@ -77,11 +77,23 @@ public fun <T> Flow<T>.flowOn(flowContext: CoroutineContext, bufferSize: Int = 1
77
77
* For more explanation of context preservation please refer to [Flow] documentation.
78
78
*
79
79
* This operator uses channel of the specific [bufferSize] in order to switch between contexts,
80
-
* but it is not guaranteed that channel will be created, implementation is free to optimize it away in case of fusing.
80
+
* but it is not guaranteed that channel will be created, implementation is free to optimize it away in case of fusing.*
81
81
*
82
-
* @throws [IllegalArgumentException] if provided context contains [Job] instance.
82
+
* This operator is deprecated without replacement because it was discovered that it doesn't play well with coroutines and flow semantics:
83
+
* 1) It doesn't prevent context elements from the downstream to leak into its body
84
+
* ```
85
+
* flowOf(1).flowWith(EmptyCoroutineContext) {
86
+
* onEach { println(kotlin.coroutines.coroutineContext[CoroutineName]) } // Will print 42
87
+
* }.flowOn(CoroutineName(42))
88
+
* ```
89
+
* 2) To avoid such leaks, new primitive should be introduced to `kotlinx.coroutines` -- the subtraction of contexts.
90
+
* And this will become a new concept to learn, maintain and explain.
91
+
* 3) It defers the execution of declarative [builder] until the moment of [collection][Flow.collect] similarly
92
+
* to `Observable.defer`. But it is unexpected because nothing in the name `flowWith` reflects this fact.
93
+
* 4) It can be confused with [flowOn] operator, though [flowWith] is much rarer.
83
94
*/
84
95
@FlowPreview
96
+
@Deprecated(message ="flowWith is deprecated without replacement, please refer to its KDoc for an explanation", level =DeprecationLevel.WARNING) // Error in beta release, removal in 1.4
0 commit comments