Skip to content

Commit bdf23f2

Browse files
committed
Optimize creation of DispatchTask for cancellable continuations (fixed)
1 parent ac48070 commit bdf23f2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/AbstractContinuation.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,17 @@ internal abstract class AbstractContinuation<in T>(
135135

136136
// see all DispatchTask.run with the same logic
137137
override fun run() {
138-
check(delegate is DispatchedContinuation)
138+
delegate as DispatchedContinuation // type assertion
139139
try {
140140
val context = delegate.context
141141
val job = if (resumeMode.isCancellableMode) context[Job] else null
142142
val state = this.state
143+
val continuation = delegate.continuation
143144
withCoroutineContext(context) {
144145
when {
145-
job != null && !job.isActive -> delegate.resumeWithException(job.getCancellationException())
146-
state is CompletedExceptionally -> delegate.resumeWithException(state.exception)
147-
else -> delegate.resume(getSuccessfulResult(state))
146+
job != null && !job.isActive -> continuation.resumeWithException(job.getCancellationException())
147+
state is CompletedExceptionally -> continuation.resumeWithException(state.exception)
148+
else -> continuation.resume(getSuccessfulResult(state))
148149
}
149150
}
150151
} catch (e: Throwable) {

0 commit comments

Comments
 (0)