Flow scope (#1227)
* Introducing flowScope, builder necessary for creating cancellation-transparent flow operators
* Incorporate flow scope into flow operators
Fixes #1218
Fixes #1128
diff --git a/kotlinx-coroutines-core/jvm/src/Builders.kt b/kotlinx-coroutines-core/jvm/src/Builders.kt
index d8f8ee3..52841cd 100644
--- a/kotlinx-coroutines-core/jvm/src/Builders.kt
+++ b/kotlinx-coroutines-core/jvm/src/Builders.kt
@@ -59,8 +59,7 @@
private val blockedThread: Thread,
private val eventLoop: EventLoop?
) : AbstractCoroutine<T>(parentContext, true) {
- override val cancelsParent: Boolean
- get() = false // it throws exception to parent instead of cancelling it
+ override val isScopedCoroutine: Boolean get() = true
override fun afterCompletionInternal(state: Any?, mode: Int) {
// wake up blocked thread
diff --git a/kotlinx-coroutines-core/jvm/src/Exceptions.kt b/kotlinx-coroutines-core/jvm/src/Exceptions.kt
index bc7e92c..7a8f385 100644
--- a/kotlinx-coroutines-core/jvm/src/Exceptions.kt
+++ b/kotlinx-coroutines-core/jvm/src/Exceptions.kt
@@ -80,8 +80,6 @@
(message!!.hashCode() * 31 + job.hashCode()) * 31 + (cause?.hashCode() ?: 0)
}
-internal actual class CoroutinesInternalError actual constructor(message: String, cause: Throwable) : Error(message, cause)
-
@Suppress("NOTHING_TO_INLINE")
internal actual inline fun Throwable.addSuppressedThrowable(other: Throwable) =
- addSuppressed(other)
+ addSuppressed(other)
\ No newline at end of file
diff --git a/kotlinx-coroutines-core/jvm/src/channels/Actor.kt b/kotlinx-coroutines-core/jvm/src/channels/Actor.kt
index ee41a0a..ffabb99 100644
--- a/kotlinx-coroutines-core/jvm/src/channels/Actor.kt
+++ b/kotlinx-coroutines-core/jvm/src/channels/Actor.kt
@@ -127,7 +127,6 @@
channel: Channel<E>,
active: Boolean
) : ChannelCoroutine<E>(parentContext, channel, active), ActorScope<E> {
- override val cancelsParent: Boolean get() = true
override fun onCancelling(cause: Throwable?) {
_channel.cancel(cause?.let {
diff --git a/kotlinx-coroutines-core/jvm/src/flow/internal/AbortFlowException.kt b/kotlinx-coroutines-core/jvm/src/flow/internal/AbortFlowException.kt
deleted file mode 100644
index 7ff34e7..0000000
--- a/kotlinx-coroutines-core/jvm/src/flow/internal/AbortFlowException.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package kotlinx.coroutines.flow.internal
-
-import kotlinx.coroutines.*
-
-internal actual class AbortFlowException : CancellationException("Flow was aborted, no more elements needed") {
- override fun fillInStackTrace(): Throwable = this
-}
diff --git a/kotlinx-coroutines-core/jvm/src/flow/internal/FlowExceptions.kt b/kotlinx-coroutines-core/jvm/src/flow/internal/FlowExceptions.kt
new file mode 100644
index 0000000..d8d4d21
--- /dev/null
+++ b/kotlinx-coroutines-core/jvm/src/flow/internal/FlowExceptions.kt
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package kotlinx.coroutines.flow.internal
+
+import kotlinx.coroutines.*
+
+internal actual class AbortFlowException : CancellationException("Flow was aborted, no more elements needed") {
+ override fun fillInStackTrace(): Throwable {
+ if (DEBUG) super.fillInStackTrace()
+ return this
+ }
+}
+
+internal actual class ChildCancelledException : CancellationException("Child of the scoped flow was cancelled") {
+ override fun fillInStackTrace(): Throwable {
+ if (DEBUG) super.fillInStackTrace()
+ return this
+ }
+}