Skip to content

Commit d23dd3d

Browse files
authored
Remove internal 'checkCompletion' function and replace it with the identical 'ensureActive' extension to reduce code duplication (#2467)
1 parent 86a0658 commit d23dd3d

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public suspend fun <T> withContext(
150150
val oldContext = uCont.context
151151
val newContext = oldContext + context
152152
// always check for cancellation of new context
153-
newContext.checkCompletion()
153+
newContext.ensureActive()
154154
// FAST PATH #1 -- new context is the same as the old one
155155
if (newContext === oldContext) {
156156
val coroutine = ScopeCoroutine(newContext, uCont)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
541541

542542
public final override suspend fun join() {
543543
if (!joinInternal()) { // fast-path no wait
544-
coroutineContext.checkCompletion()
544+
coroutineContext.ensureActive()
545545
return // do not suspend
546546
}
547547
return joinSuspend() // slow-path wait

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import kotlin.coroutines.intrinsics.*
3030
*/
3131
public suspend fun yield(): Unit = suspendCoroutineUninterceptedOrReturn sc@ { uCont ->
3232
val context = uCont.context
33-
context.checkCompletion()
33+
context.ensureActive()
3434
val cont = uCont.intercepted() as? DispatchedContinuation<Unit> ?: return@sc Unit
3535
if (cont.dispatcher.isDispatchNeeded(context)) {
3636
// this is a regular dispatcher -- do simple dispatchYield
@@ -50,8 +50,3 @@ public suspend fun yield(): Unit = suspendCoroutineUninterceptedOrReturn sc@ { u
5050
}
5151
COROUTINE_SUSPENDED
5252
}
53-
54-
internal fun CoroutineContext.checkCompletion() {
55-
val job = get(Job)
56-
if (job != null && !job.isActive) throw job.getCancellationException()
57-
}

0 commit comments

Comments
 (0)