@@ -21,7 +21,7 @@ private const val RESUMED = 2
21
21
private inline val Int .decision get() = this shr DECISION_SHIFT
22
22
private inline val Int .index get() = this and INDEX_MASK
23
23
@Suppress(" NOTHING_TO_INLINE" )
24
- private inline fun construct (decision : Int , index : Int ) = decision shl DECISION_SHIFT + index
24
+ private inline fun construct (decision : Int , index : Int ) = ( decision shl DECISION_SHIFT ) + index
25
25
26
26
@JvmField
27
27
@SharedImmutable
@@ -182,7 +182,7 @@ internal open class CancellableContinuationImpl<in T>(
182
182
_state .loop { state ->
183
183
if (state !is NotCompleted ) return false // false if already complete or cancelling
184
184
// Active -- update to final state
185
- val update = CancelledContinuation (this , cause, handled = state is CancelHandler )
185
+ val update = CancelledContinuation (this , cause, handled = state is CancelHandler || state is Segment < * > )
186
186
if (! _state .compareAndSet(state, update)) return @loop // retry on cas failure
187
187
// Invoke cancel handler if it was present
188
188
(state as ? CancelHandler )?.let { callCancelHandler(it, cause) }
@@ -224,9 +224,9 @@ internal open class CancellableContinuationImpl<in T>(
224
224
callCancelHandlerSafely { handler.invoke(cause) }
225
225
226
226
fun callSegmentOnCancellation (segment : Segment <* >, cause : Throwable ? ) {
227
- val index = _decisionAndIndex .getAndUpdate { construct(it.decision, NO_INDEX ) }.index
228
- check(index != NO_INDEX ) { " The index for segment.invokeOnCancellation(..) is broken" }
229
- callCancelHandlerSafely { segment.invokeOnCancellation(index, cause) }
227
+ // val index = _decisionAndIndex.getAndUpdate { construct(it.decision, NO_INDEX) }.index
228
+ // check(index != NO_INDEX) { "The index for segment.invokeOnCancellation(..) is broken" }
229
+ // callCancelHandlerSafely { segment.invokeOnCancellation(index, cause) }
230
230
}
231
231
232
232
@@ -368,7 +368,7 @@ internal open class CancellableContinuationImpl<in T>(
368
368
is Active -> {
369
369
if (_state .compareAndSet(state, handler)) return // quit on cas success
370
370
}
371
- is CancelHandler -> multipleHandlersError(handler, state)
371
+ is CancelHandler , is Segment < * > -> multipleHandlersError(handler, state)
372
372
is CompletedExceptionally -> {
373
373
/*
374
374
* Continuation was already cancelled or completed exceptionally.
0 commit comments