Skip to content

Instantly share code, notes, and snippets.

@abdurahmanadilovic
Created December 17, 2017 20:48
Show Gist options
  • Save abdurahmanadilovic/a38b5e4d93fd70adb82eb2a9c9cbe711 to your computer and use it in GitHub Desktop.
Save abdurahmanadilovic/a38b5e4d93fd70adb82eb2a9c9cbe711 to your computer and use it in GitHub Desktop.
Exception handling with async coroutine
async(parentJob + UI) {
val task = async(parentJob + CommonPool) {
RestClient.apiDefinition.listPosts().execute()
}
val result = task.await()
val numberOfPosts = "number of posts ${result.body()?.size}"
numberOfPostsTextView.text = numberOfPosts
}.invokeOnCompletion { it: Throwable? ->
alertWithOkButton("Caught an exception inside invoke on completion callback")
it?.printStackTrace()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment