Skip to content

Commit cc6e1a2

Browse files
committed
Implement ScopeCoroutine in SupervisorCoroutine
Fixes #915
1 parent 703a286 commit cc6e1a2

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

kotlinx-coroutines-core/common/src/AbstractCoroutine.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public abstract class AbstractCoroutine<in T>(
3737
/**
3838
* Context of the parent coroutine.
3939
*/
40-
4140
@JvmField
4241
protected val parentContext: CoroutineContext,
4342
active: Boolean = true
@@ -53,7 +52,7 @@ public abstract class AbstractCoroutine<in T>(
5352
*/
5453
public override val coroutineContext: CoroutineContext get() = context
5554

56-
override val isActive: Boolean get() = super<JobSupport>.isActive
55+
override val isActive: Boolean get() = super.isActive
5756

5857
/**
5958
* Initializes parent job from the `parentContext` of this coroutine that was passed to it during construction.

kotlinx-coroutines-core/common/src/Supervisor.kt

+5-14
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
package kotlinx.coroutines
88

9+
import kotlinx.coroutines.internal.*
910
import kotlinx.coroutines.intrinsics.*
1011
import kotlin.coroutines.*
1112
import kotlin.coroutines.intrinsics.*
12-
import kotlin.jvm.*
1313

1414
/**
1515
* Creates a new _supervisor_ job object in an active state.
@@ -56,18 +56,9 @@ private class SupervisorJobImpl(parent: Job?) : JobImpl(parent) {
5656
override fun childCancelled(cause: Throwable): Boolean = false
5757
}
5858

59-
private class SupervisorCoroutine<R>(
60-
parentContext: CoroutineContext,
61-
@JvmField val uCont: Continuation<R>
62-
) : AbstractCoroutine<R>(parentContext, true) {
63-
override val defaultResumeMode: Int get() = MODE_DIRECT
59+
private class SupervisorCoroutine<in T>(
60+
context: CoroutineContext,
61+
uCont: Continuation<T>
62+
) : ScopeCoroutine<T>(context, uCont) {
6463
override fun childCancelled(cause: Throwable): Boolean = false
65-
66-
@Suppress("UNCHECKED_CAST")
67-
internal override fun onCompletionInternal(state: Any?, mode: Int, suppressed: Boolean) {
68-
if (state is CompletedExceptionally)
69-
uCont.resumeUninterceptedWithExceptionMode(state.cause, mode)
70-
else
71-
uCont.resumeUninterceptedMode(state as R, mode)
72-
}
7364
}

kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryTest.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class StackTraceRecoveryTest : TestBase() {
180180
"\t(Coroutine boundary)\n" +
181181
"\tat kotlinx.coroutines.DeferredCoroutine.await\$suspendImpl(Builders.common.kt:99)\n" +
182182
"\tat kotlinx.coroutines.exceptions.StackTraceRecoveryTest.innerMethod(StackTraceRecoveryTest.kt:158)\n" +
183+
"\tat kotlinx.coroutines.exceptions.StackTraceRecoveryTest\$outerScopedMethod\$2\$1.invokeSuspend(StackTraceRecoveryTest.kt:193)\n" +
183184
"\tat kotlinx.coroutines.exceptions.StackTraceRecoveryTest\$outerScopedMethod\$2.invokeSuspend(StackTraceRecoveryTest.kt:151)\n" +
184185
"\tat kotlinx.coroutines.exceptions.StackTraceRecoveryTest\$testCoroutineScope\$1.invokeSuspend(StackTraceRecoveryTest.kt:141)\n",
185186
"Caused by: kotlinx.coroutines.RecoverableTestException\n" +
@@ -217,7 +218,10 @@ class StackTraceRecoveryTest : TestBase() {
217218
}
218219

219220
private suspend fun outerScopedMethod(deferred: Deferred<Nothing>, vararg traces: String) = coroutineScope {
220-
innerMethod(deferred, *traces)
221+
supervisorScope {
222+
innerMethod(deferred, *traces)
223+
assertTrue(true)
224+
}
221225
assertTrue(true)
222226
}
223227

0 commit comments

Comments
 (0)