Skip to content

Instantly share code, notes, and snippets.

@dmytrodanylyk
Last active October 10, 2017 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmytrodanylyk/b325e0ff3cd65e452097c5da91514e7a to your computer and use it in GitHub Desktop.
Save dmytrodanylyk/b325e0ff3cd65e452097c5da91514e7a to your computer and use it in GitHub Desktop.
private fun loadData() = launch(uiContext) {
view.showLoading() // ui thread
try {
val task = async(bgContext) { dataProvider.loadData("Task") }
val result = task.await() // non ui thread, suspend until task is finished
view.showData(result) // ui thread
} catch (e: RuntimeException) {
e.printStackTrace()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment