New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suspendCancellableCoroutine returns an internal CompletedWithCancellation object instead of the actual resulting type #1966
Comments
Upon investigating this a bit more, I noticed that if the listener is invoked inside a
Why does using a |
I fail to reproduce it in a standalone non-Android project. Does it reproduce with |
Yes, it happens with I pinpointed the issue to this line:
If I change this to use the extension method from
Why doesn't the former work in this case? |
There's a bug somewhere, but I cannot reproduce it. |
Here's some more info about my setup, hopefully it helps ya. I run it on Pixel 3a API 29 emulator, with Android targetSdkVersion set to 29. AGP 3.6.3 in use, Kotlin version is 1.3.72, and here are the related Kotlin dependencies:
|
Can you publish a mini-project that reproduces it? |
Here you go: https://github.com/manabreak/coroutinebugtest |
Stacktrace:
|
Note: It seems to be a side effect of the immediate UI dispatcher. It might already be fixed in #1937 |
…ntinuation with onCancellation block Fixes #1966
I am still seeing this issue in Kotlin 1.3.71, and had to include the |
…ntinuation with onCancellation block (Kotlin#1967) Fixes Kotlin#1966
I ran into a weird issue that manifested itself when I updated the
kotlinx-coroutines-core
dependency from 1.3.2 to 1.3.3. However, the self-contained example below reproduces the issue with 1.3.2 as well.I have an extension method for a callback-based operation queue. This extension method uses
suspendCancellableCoroutine
to wrap the callback usage and to convert it to a suspend function. Now, it all works otherwise, but the resulting object that is returned from the suspending function is not of typeT
, butCompletedWithCancellation<T>
, which is a private class of the coroutine library.The weird thing is, if I call
c.resume("Foobar" as T, {})
inside thesuspendCancellableCoroutine
, it works just fine. When using the callback routine, the value is aString
before passing to toc.resume()
, but it gets wrapped in aCompletedWithCancellation
object.Here's the code that reproduces the issue:
Do note that just before calling
c.resume()
, the type ofresult
isString
, as it should be. However, it's notString
ingetFoo()
once the suspend function completes. What causes this?The text was updated successfully, but these errors were encountered: