Created
December 17, 2017 20:48
-
-
Save abdurahmanadilovic/a38b5e4d93fd70adb82eb2a9c9cbe711 to your computer and use it in GitHub Desktop.
Exception handling with async coroutine
This file contains hidden or 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
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