Skip to content

Commit ee3776a

Browse files
committed
Refactoring: Improve DispatchedTask.run a bit
1 parent dc8eeb0 commit ee3776a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ internal abstract class DispatchedTask<in T>(
4141
val state = takeState() // NOTE: Must take state in any case, even if cancelled
4242
withCoroutineContext(context, delegate.countOrElement) {
4343
val exception = getExceptionalResult(state)
44-
val job = if (resumeMode.isCancellableMode) context[Job] else null
4544
/*
4645
* Check whether continuation was originally resumed with an exception.
4746
* If so, it dominates cancellation, otherwise the original exception
4847
* will be silently lost.
4948
*/
50-
if (exception == null && job != null && !job.isActive) {
49+
val job = if (exception == null && resumeMode.isCancellableMode) context[Job] else null
50+
if (job != null && !job.isActive) {
5151
val cause = job.getCancellationException()
5252
cancelResult(state, cause)
5353
continuation.resumeWithStackTrace(cause)
5454
} else {
55-
if (exception != null) continuation.resumeWithException(exception)
56-
else continuation.resume(getSuccessfulResult(state))
55+
if (exception != null) {
56+
continuation.resumeWithException(exception)
57+
} else {
58+
continuation.resume(getSuccessfulResult(state))
59+
}
5760
}
5861
}
5962
} catch (e: Throwable) {

0 commit comments

Comments
 (0)