Skip to content

Instantly share code, notes, and snippets.

Last active October 10, 2017 04:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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