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
Properly enforce flow invariant when flow is used from "suspend fun m… (#1426)
* Properly enforce flow invariant when flow is used from "suspend fun main" or artificially started coroutine (e.g. by block.startCoroutine(...))
Fixes#1421
Copy file name to clipboardExpand all lines: kotlinx-coroutines-core/common/src/flow/internal/SafeCollector.kt
+7-1
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,13 @@ internal class SafeCollector<T>(
81
81
"FlowCollector is not thread-safe and concurrent emissions are prohibited. To mitigate this restriction please use 'channelFlow' builder instead of 'flow'"
82
82
)
83
83
}
84
-
count +1
84
+
85
+
/*
86
+
* If collect job is null (-> EmptyCoroutineContext, probably run from `suspend fun main`), then invariant is maintained
87
+
* (common transitive parent is "null"), but count check will fail, so just do not count job context element when
0 commit comments