Last active
October 10, 2017 04:26
-
-
Save dmytrodanylyk/ad808edd189f0d9fef223850aaa152ac to your computer and use it in GitHub Desktop.
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
val exceptionHandler: CoroutineContext = CoroutineExceptionHandler { _, throwable -> throwable.printStackTrace() } | |
private fun loadData() = launch(uiContext + exceptionHandler) { | |
view.showLoading() // ui thread | |
val task = async(bgContext) { dataProvider.loadData("Task") } | |
val result = task.await() // non ui thread, suspend until the task is finished | |
view.showData(result) // ui thread | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment