MCE 2017: Svetlana Isakova, Coroutines in Kotlin

Поделиться
HTML-код
  • Опубликовано: 25 янв 2025

Комментарии • 10

  • @caffeinejavacode1475
    @caffeinejavacode1475 3 года назад

    Can coroutines take executors like Completeable Future?
    If I want a separate thread for computation?

  • @bisujin1685
    @bisujin1685 7 лет назад

    I cannot find UI in the launch(), but i use runOnUiThread instead

  • @alekseimulin6151
    @alekseimulin6151 7 лет назад

    Ok, interesting concept but bow to cancel coroutine in the example presented?
    async {
    val image = loadImage(url).await()
    myUI.setImage(image)
    }
    And how to handle "failure" case when error happens while loading? What if we should distinguish between several type of errors e.g. server errors, no network connection, etc? Is there stack allocated for coroutines?

    • @pixelPlex
      @pixelPlex 7 лет назад

      Coroutines does have its own stack for debugging purposes. The "async" function returns a "Deferred" object, which can be cancelled by calling the "cancel" function and passing through a Throwable as a parameter. Note that "await" doesn't need to be called in the "async" block. Below is a loose coupled Async/Await example:
      fun main(args: Array) {
      val deferred = (1..1_000_000).map { n ->
      async(CommonPool) { asyncWorkload(n) }
      }
      runBlocking {
      deferred.take(20).forEach { println("Num: ${it.await()}") }
      }
      }
      private suspend fun asyncWorkload(num: Int): Int {
      delay(1000)
      return num
      }

    • @ayudakov
      @ayudakov 7 лет назад

      See 24:05 about exception handling. You can use regular try/catch.

    • @sprissetto
      @sprissetto 7 лет назад +1

      isn't it answered at 33:50?

  • @dkozinsk
    @dkozinsk 6 лет назад

    Thank you for great lecture! Would you be so kind and publish presentation slides as well?

  • @marta_na_moto
    @marta_na_moto 7 лет назад +1

    Thanks for publishing this :) One small advice: its really hard to listen to it due to a hard accent of a presenter :(

    • @TheNihaonyan
      @TheNihaonyan 6 лет назад

      Trust me it's not because of accent, she's just hard to listen at any language

  • @АнтонИцкович-х7у
    @АнтонИцкович-х7у 7 лет назад +2

    Милаха