Last active
November 23, 2017 17:25
-
-
Save erikjhordan-rey/fabfc7e4227f836050223f541e76ccdb to your computer and use it in GitHub Desktop.
This class is an extension to facilitate the use of Retrofit callback responses .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import retrofit2.Call | |
import retrofit2.Callback | |
import retrofit2.Response | |
fun <T> Call<T>.execute(success: (response: Response<T>) -> Unit, | |
failure: (t: Throwable) -> Unit) { | |
enqueue(object : Callback<T> { | |
override fun onResponse(call: Call<T>?, response: Response<T>) = success(response) | |
override fun onFailure(call: Call<T>?, t: Throwable) = failure(t) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage it!