Skip to content

Instantly share code, notes, and snippets.

@galex
Created May 18, 2018 06:46
Show Gist options
  • Save galex/d65d23ff8a4d1766268696555fd5b915 to your computer and use it in GitHub Desktop.
Save galex/d65d23ff8a4d1766268696555fd5b915 to your computer and use it in GitHub Desktop.
async(UI) {
// before using https://github.com/JakeWharton/retrofit2-kotlin-coroutines-adapter
val call: Call<ApiResponse<List<VideoExtra>>> = service.getVideoExtras(userId)
val response: Response<ApiResponse<List<VideoExtra>>> = bg { call.execute() }.await()
// When using it, our code looks much better
val deferred: Deferred<Response<ApiResponse<List<VideoExtra>>>> = service.getVideoExtras(userId)
val response: Response<ApiResponse<List<VideoExtra>>> = deferred.await()
// using the response's data to set the value of LiveData(), etc...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment