@@ -1034,7 +1034,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1034
1034
private val job : JobSupport
1035
1035
) : CancellableContinuationImpl<T>(delegate, MODE_CANCELLABLE ) {
1036
1036
override fun getContinuationCancellationCause (parent : Job ): Throwable {
1037
- val state = job.state.unboxState()
1037
+ val state = job.state
1038
1038
/*
1039
1039
* When the job we are waiting for had already completely completed exceptionally or
1040
1040
* is failing, we shall use its root/completion cause for await's result.
@@ -1059,7 +1059,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1059
1059
public val isCompletedExceptionally: Boolean get() = state is CompletedExceptionally
1060
1060
1061
1061
public fun getCompletionExceptionOrNull (): Throwable ? {
1062
- val state = this .state.unboxState()
1062
+ val state = this .state
1063
1063
check(state !is Incomplete ) { " This job has not completed yet" }
1064
1064
return state.exceptionOrNull
1065
1065
}
@@ -1068,10 +1068,10 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1068
1068
* @suppress **This is unstable API and it is subject to change.**
1069
1069
*/
1070
1070
internal fun getCompletedInternal (): Any? {
1071
- val state = this .state.unboxState()
1071
+ val state = this .state
1072
1072
check(state !is Incomplete ) { " This job has not completed yet" }
1073
1073
if (state is CompletedExceptionally ) throw state.cause
1074
- return state
1074
+ return state.unboxState()
1075
1075
}
1076
1076
1077
1077
/* *
@@ -1080,11 +1080,11 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1080
1080
internal suspend fun awaitInternal (): Any? {
1081
1081
// fast-path -- check state (avoid extra object creation)
1082
1082
while (true ) { // lock-free loop on state
1083
- val state = this .state.unboxState()
1083
+ val state = this .state
1084
1084
if (state !is Incomplete ) {
1085
1085
// already complete -- just return result
1086
1086
if (state is CompletedExceptionally ) throw state.cause
1087
- return state
1087
+ return state.unboxState()
1088
1088
1089
1089
}
1090
1090
if (startInternal(state) >= 0 ) break // break unless needs to retry
@@ -1116,10 +1116,12 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1116
1116
if (state !is Incomplete ) {
1117
1117
// already complete -- select result
1118
1118
if (select.trySelect(null )) {
1119
- if (state is CompletedExceptionally )
1119
+ if (state is CompletedExceptionally ) {
1120
1120
select.resumeSelectCancellableWithException(state.cause)
1121
- else
1122
- block.startCoroutineUnintercepted(state as T , select.completion)
1121
+ }
1122
+ else {
1123
+ block.startCoroutineUnintercepted(state.unboxState() as T , select.completion)
1124
+ }
1123
1125
}
1124
1126
return
1125
1127
}
@@ -1136,12 +1138,12 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1136
1138
*/
1137
1139
@Suppress(" UNCHECKED_CAST" )
1138
1140
internal fun <T , R > selectAwaitCompletion (select : SelectInstance <R >, block : suspend (T ) -> R ) {
1139
- val state = this .state.unboxState()
1141
+ val state = this .state
1140
1142
// Note: await is non-atomic (can be cancelled while dispatched)
1141
1143
if (state is CompletedExceptionally )
1142
1144
select.resumeSelectCancellableWithException(state.cause)
1143
1145
else
1144
- block.startCoroutineCancellable(state as T , select.completion)
1146
+ block.startCoroutineCancellable(state.unboxState() as T , select.completion)
1145
1147
}
1146
1148
}
1147
1149
@@ -1244,14 +1246,15 @@ private class ResumeAwaitOnCompletion<T>(
1244
1246
private val continuation : AbstractContinuation <T >
1245
1247
) : JobNode<JobSupport>(job) {
1246
1248
override fun invoke (cause : Throwable ? ) {
1247
- val state = job.state.unboxState()
1249
+ val state = job.state
1250
+ check(state !is Incomplete )
1248
1251
if (state is CompletedExceptionally ) {
1249
1252
// Resume with exception in atomic way to preserve exception
1250
1253
continuation.resumeWithExceptionMode(state.cause, MODE_ATOMIC_DEFAULT )
1251
1254
} else {
1252
1255
// Resuming with value in a cancellable way (AwaitContinuation is configured for this mode).
1253
1256
@Suppress(" UNCHECKED_CAST" )
1254
- continuation.resume(state as T )
1257
+ continuation.resume(state.unboxState() as T )
1255
1258
}
1256
1259
}
1257
1260
override fun toString () = " ResumeAwaitOnCompletion[$continuation ]"
0 commit comments