Skip to content

Instantly share code, notes, and snippets.

@dmytrodanylyk
Last active October 10, 2017 04:25
Show Gist options
  • Select an option

  • Save dmytrodanylyk/fd11bb50cc63d7d90abc7f31f8751bd1 to your computer and use it in GitHub Desktop.

Select an option

Save dmytrodanylyk/fd11bb50cc63d7d90abc7f31f8751bd1 to your computer and use it in GitHub Desktop.

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
    @@ -3,7 +3,7 @@ data class Result<out T>(val success: T? = null, val error: Throwable? = null)
    private fun loadData() = launch(uiContext) {
    view.showLoading() // ui thread

    val task = async(ioContext) { dataProvider.loadData("Task") }
    val task = async(bgContext) { dataProvider.loadData("Task") }
    val result: Result<String> = task.await() // non ui thread, suspend until the task is finished

    if (result.success != null) {
  2. dmytrodanylyk revised this gist Oct 9, 2017. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion MainPresenter.kt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    data class Result<out T>(val success: T? = null, val error: Throwable? = null)


    private fun loadData() = launch(uiContext) {
    view.showLoading() // ui thread

  3. dmytrodanylyk created this gist Oct 9, 2017.
    15 changes: 15 additions & 0 deletions MainPresenter.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    data class Result<out T>(val success: T? = null, val error: Throwable? = null)


    private fun loadData() = launch(uiContext) {
    view.showLoading() // ui thread

    val task = async(ioContext) { dataProvider.loadData("Task") }
    val result: Result<String> = task.await() // non ui thread, suspend until the task is finished

    if (result.success != null) {
    view.showData(result.success) // ui thread
    } else if (result.error != null) {
    result.error.printStackTrace()
    }
    }