Skip to content

Commit 74d0a78

Browse files
committed
Let's see how it works :)
1 parent 87b45d2 commit 74d0a78

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private const val RESUMED = 2
2121
private inline val Int.decision get() = this shr DECISION_SHIFT
2222
private inline val Int.index get() = this and INDEX_MASK
2323
@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
2525

2626
@JvmField
2727
@SharedImmutable
@@ -182,7 +182,7 @@ internal open class CancellableContinuationImpl<in T>(
182182
_state.loop { state ->
183183
if (state !is NotCompleted) return false // false if already complete or cancelling
184184
// 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<*>)
186186
if (!_state.compareAndSet(state, update)) return@loop // retry on cas failure
187187
// Invoke cancel handler if it was present
188188
(state as? CancelHandler)?.let { callCancelHandler(it, cause) }
@@ -224,9 +224,9 @@ internal open class CancellableContinuationImpl<in T>(
224224
callCancelHandlerSafely { handler.invoke(cause) }
225225

226226
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) }
230230
}
231231

232232

@@ -368,7 +368,7 @@ internal open class CancellableContinuationImpl<in T>(
368368
is Active -> {
369369
if (_state.compareAndSet(state, handler)) return // quit on cas success
370370
}
371-
is CancelHandler -> multipleHandlersError(handler, state)
371+
is CancelHandler, is Segment<*> -> multipleHandlersError(handler, state)
372372
is CompletedExceptionally -> {
373373
/*
374374
* Continuation was already cancelled or completed exceptionally.

0 commit comments

Comments
 (0)