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

Joan Colmenero

10/19/2019, 4:07 PM
Hello I'm moving to the new version of retrofit and I was using a convertor that was creating a
ResultWrapperT
from
CallT
but now reading this answer [1] from stackoverflow then I realized that if I'm using
suspended fun
I do not have to add the
CallT
so, how do I do the change now? I was using this method :
Copy code
fun <reified T:Any> execute(function: () -> Call<T>): ResultWrapperT =
        try {
            when (T::class) {
                Unit::class -> function().execute().let {
                    ResultWrapper.Success(Unit as T)
                }
                else -> function().execute().body()?.let {
                    ResultWrapper.Success(it)
                } ?: ResultWrapper.Error(Exception("no body there"))
            }
        } catch (e: Exception) {
            ResultWrapper.Exception(e)
        }
Any idea? The problem now is that as it's not a
CallT
I do not have the
execute()
method... [1] : https://stackoverflow.com/a/57810074/4329781
k

Kroppeb

10/19/2019, 4:09 PM
Remove the
execute()
?
j

Joan Colmenero

10/19/2019, 4:10 PM
But how do I check if it contains body or if it's success then?
I was using execute to check the body or if it was a Unit
k

Kroppeb

10/19/2019, 4:11 PM
I'm guessing
function
now returns
T?
. It might also be useful to constrain T to be non nullable:
<reified T:Any>
wait something looks wrong with your function signature
shouldn't your function be inline if it's reified or am I missing something?
j

Joan Colmenero

10/19/2019, 4:15 PM
sorry mistyped yep
Let me explain the problem, the problem is : I was trying to use retrofit as :
@GET("/") suspended fun pew(something) : ResultWrapper<POJO>
but was not working, then the problem is that I can not do that... So I have to do like a "migration" or whatever you want to call from
@GET("/") suspended fun pew(something) : POJO
and then change it to
ResultWrapper<POJO>
is it possible?
You got me?
@Kroppeb any idea??
k

Kroppeb

10/19/2019, 9:25 PM
No not really
4 Views