I have a suspend fun that for some reason returns ...
# coroutines
l
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
What type were you expecting?
l
I was expecting a list of models which i fetch from a database
d
How do you know it returns Unit? I'm guessing it throws some sort of casting exception.
l
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
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
I see, so there might actually be no problems in that case
d
Yes
l
Alright, thanks i will continue debugging
j
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
Ah, didn't know that. Will update.