Skip to content

Commit 36eee68

Browse files
committed
Remove internal 'checkCompletion' function and replace it with the identical 'ensureActive' extension to reduce code duplication
1 parent 5954e40 commit 36eee68

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

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

0 commit comments

Comments
 (0)