You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
suspendCancellableCoroutine<Unit> { c ->
c.invokeOnCancellation {
println(it)
}
c.cancel()
}
Semantically the same snippet prints CancellationException:
suspendCancellableCoroutine<Unit> { c ->
c.cancel()
c.invokeOnCancellation {
println(it)
}
}
CompletionHandler contract:
* The meaning of `cause` that is passed to the handler:
* * Cause is `null` when the job has completed normally.
* * Cause is an instance of [CancellationException] when the job was cancelled _normally_.
* **It should not be treated as an error**. In particular, it should not be reported to error logs.
* * Otherwise, the job had _failed_.
The text was updated successfully, but these errors were encountered:
This behaviour seems to be the legacy from the times when CancellableContinuation was an instance of Job (pre 0.22.x versions) and we preserved CompletionHandler ABI.
Tho for CancellableContinuation that does not have invokeOnCompletion the underlying cause is never null.
suspendCancellableCoroutine<Unit> { c ->
c.invokeOnCancellation {
println("Invoked") // Printed
}
c.invokeOnCancellation { expectUnreached() } // Triggers ISE
}
suspendCancellableCoroutine<Unit> { c ->
c.invokeOnCancellation {
println("Invoked") // Not printed
}
c.resumeWith(Result.failure(IllegalStateException()))
}
qwwdfsad
changed the title
CacnellableContinuation.invokeOnCancellation cause is inconsistent and breaks its own contract
CancellableContinuation.invokeOnCancellation cause is inconsistent and breaks its own contract
Jun 15, 2020
As a side note. I've rechecked both in resource-cancel branch (which reworks a significant chunk of CacncellableContinuationImpl machinery):
The first inconsistency with cause is still present.
The second inconsistency with throwing from invokeOnCancellation is gone, but what should happen if invokeOnCancellation throws an exception is still an open design issue in PR Breaking: Get rid of atomic cancellation and provide a replacement #1937 and that's the reason why it is still a draft.
Steps to reproduce:
null
CancellationException
:CompletionHandler
contract:The text was updated successfully, but these errors were encountered: