Skip to content

Instantly share code, notes, and snippets.

@demonar
Created October 9, 2019 00:23
Show Gist options
  • Save demonar/ee10b0344a11b203dda84ae1460dd636 to your computer and use it in GitHub Desktop.
Save demonar/ee10b0344a11b203dda84ae1460dd636 to your computer and use it in GitHub Desktop.
inline fun <reified T> Call<T>.enqueue(crossinline result: (Result<T>) -> Unit) {
enqueue(object: Callback<T> {
override fun onFailure(call: Call<T>, error: Throwable) {
result(Result.Failure(call, error))
}
override fun onResponse(call: Call<T>, response: Response<T>) {
result(Result.Success(call, response))
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment