https://kotlinlang.org logo
#coroutines
Title
# coroutines
l

Loránd

06/23/2019, 11:39 AM
I have a suspend fun that for some reason returns Kotlin.Unit when it is done and not the type i expected it to return, anyone had this problem before?
d

Dominaezzz

06/23/2019, 11:46 AM
What type were you expecting?
l

Loránd

06/23/2019, 11:49 AM
I was expecting a list of models which i fetch from a database
d

Dominaezzz

06/23/2019, 11:51 AM
How do you know it returns Unit? I'm guessing it throws some sort of casting exception.
l

Loránd

06/23/2019, 11:54 AM
I dont know if i am debugging this correctly but i am using some breakpoints to step through the code and when i am at that method the IDE says the type of the returned value is Kotlin.Unit. I dont know if this might be an IDE issue or something.
d

Dominaezzz

06/23/2019, 11:54 AM
Oh!
This
suspend fun getUsers(): List<User>
translates to
fun getUsers(cont: Continuation<List<User>>): Any?
underneath.
That might be why IDE is showing Unit.
AFAIK, debugging with coroutines and suspend functions isn't fully complete.
l

Loránd

06/23/2019, 11:57 AM
I see, so there might actually be no problems in that case
d

Dominaezzz

06/23/2019, 11:57 AM
Yes
l

Loránd

06/23/2019, 11:59 AM
Alright, thanks i will continue debugging
j

jw

06/23/2019, 2:35 PM
That signature isn't correct. suspend functions after transformation return Any?
The return type becomes a union type of the actual return type (for synchronous returns) and a marker instance indicating suspension happened
d

Dominaezzz

06/23/2019, 2:37 PM
Ah, didn't know that. Will update.
4 Views