https://kotlinlang.org logo
Title
l

Lalit Sagar

11/02/2020, 8:14 AM
I went through the documentation of
suspendCancellableCoroutine
. It mentions that this function throws a
CancellationException
if the coroutine is cancelled or completed while suspended. In which case the coroutine is completed while suspended?
e

elizarov

11/02/2020, 10:34 AM
This case is not trivial to set up. It never happens if you use coroutine builders from
kotlinx.coroutines
. Take a look at this test that tests for this schenario: https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/common/test/CancellableContinuationTest.kt#L120-L141
:thank-you: 1
l

Lalit Sagar

11/02/2020, 4:32 PM
Thanks @elizarov. This unit test example really helped