aboutsummaryrefslogtreecommitdiffstats
path: root/kotlinx-coroutines-core/common/src/flow/internal/SafeCollector.kt
diff options
context:
space:
mode:
Diffstat (limited to 'kotlinx-coroutines-core/common/src/flow/internal/SafeCollector.kt')
-rw-r--r--kotlinx-coroutines-core/common/src/flow/internal/SafeCollector.kt8
1 files changed, 7 insertions, 1 deletions
diff --git a/kotlinx-coroutines-core/common/src/flow/internal/SafeCollector.kt b/kotlinx-coroutines-core/common/src/flow/internal/SafeCollector.kt
index 09a63781..8761058e 100644
--- a/kotlinx-coroutines-core/common/src/flow/internal/SafeCollector.kt
+++ b/kotlinx-coroutines-core/common/src/flow/internal/SafeCollector.kt
@@ -81,7 +81,13 @@ internal class SafeCollector<T>(
"FlowCollector is not thread-safe and concurrent emissions are prohibited. To mitigate this restriction please use 'channelFlow' builder instead of 'flow'"
)
}
- count + 1
+
+ /*
+ * If collect job is null (-> EmptyCoroutineContext, probably run from `suspend fun main`), then invariant is maintained
+ * (common transitive parent is "null"), but count check will fail, so just do not count job context element when
+ * flow is collected from EmptyCoroutineContext
+ */
+ if (collectJob == null) count else count + 1
}
if (result != collectContextSize) {
error(