Skip to content

Instantly share code, notes, and snippets.

@dmytrodanylyk
Last active October 10, 2017 04:41

Revisions

  1. dmytrodanylyk revised this gist Oct 10, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MainPresenter.kt
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ private fun loadData() = launch(uiContext) {
    val result = task.await() // non ui thread, suspend until task is finished

    view.showData(result) // ui thread
    } catch (e: IllegalArgumentException) {
    } catch (e: RuntimeException) {
    e.printStackTrace()
    }
    }
  2. dmytrodanylyk revised this gist Oct 10, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MainPresenter.kt
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ private fun loadData() = launch(uiContext) {
    view.showLoading() // ui thread

    try {
    val task = async(ioContext) { dataProvider.loadData("Task") }
    val task = async(bgContext) { dataProvider.loadData("Task") }
    val result = task.await() // non ui thread, suspend until task is finished

    view.showData(result) // ui thread
  3. dmytrodanylyk created this gist Oct 9, 2017.
    12 changes: 12 additions & 0 deletions MainPresenter.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    private fun loadData() = launch(uiContext) {
    view.showLoading() // ui thread

    try {
    val task = async(ioContext) { dataProvider.loadData("Task") }
    val result = task.await() // non ui thread, suspend until task is finished

    view.showData(result) // ui thread
    } catch (e: IllegalArgumentException) {
    e.printStackTrace()
    }
    }