Це відео не доступне.
Перепрошуємо.

Avoid THIS Fatal Coroutine Mistake in Kotlin

Поділитися
Вставка
  • Опубліковано 3 січ 2023

КОМЕНТАРІ • 27

  • @libinmathew2566
    @libinmathew2566 Рік тому +12

    An async block runs only in parallel if two blocks are in different threads. Otherwise, it runs concurrently.Above eg, it runs in parallel because the delay function block first async and thread become free and thread can be used by the second async. You can check it by removing the delay function function.

  • @ayoubmazrou8800
    @ayoubmazrou8800 Рік тому +3

    I was making 2 blocks of launch {} for each function . To run it in parallel

  • @RinoSss
    @RinoSss Рік тому +4

    The point here is not that using deferred() allow us to perform async code, because firstly we have to know what basically executing code with deferral means.
    What it really matters is that we actually perform both network calls in 2 separated and concurrent coroutines.
    As the execution finishes, whether or not we are interested in their return value that's when we speak about using a deferred() or a common launch() block.
    Great insight by the way

  • @ruavaen
    @ruavaen Рік тому +2

    Nice opportunity to show the deferred requests for when you can make parallel network requests but you need the result of all of them to proceed

  • @azizbekrasulmetov9293
    @azizbekrasulmetov9293 Рік тому +2

    The point here is to launch coroutine separately to achieve concurrency

  • @benjamin1313
    @benjamin1313 Рік тому

    Just gotten into learning about coroutines. Thanks for the great tip.

  • @sushilkafle6501
    @sushilkafle6501 Рік тому

    Woww... this made the concept crystal clear... hats off 👏 🙌

  • @jaidynbelbin4863
    @jaidynbelbin4863 Рік тому +1

    Just like async let in Swift. Nice little video 🙂

  • @aapipcps2311
    @aapipcps2311 Рік тому +1

    this help me to understanding coroutine, thanks

  • @azizbekrasulmetov9293
    @azizbekrasulmetov9293 Рік тому +1

    We can achieve it with launch as well if it doesn't return anything!

  • @angelomarzocchi4202
    @angelomarzocchi4202 Рік тому

    This man is the goat

  • @dhruvsharma8839
    @dhruvsharma8839 Рік тому

    Without asyn it will come in single coroutine where as using async it will make both calls parallel.

  • @shlusiak
    @shlusiak Рік тому +3

    From "Fatal mistake" to "mistake" to "performance tip"... Bit sensational title, no?

  •  Рік тому

    Very nice 👍

  • @zekininadresi
    @zekininadresi Рік тому

    async-await is to decompose a task into potentially multiple running subtasks, right? so how this can be used to run independent tasks?

  • @leolr111
    @leolr111 Рік тому

    This would be necessary when I use retrofit network calls?

  • @josemejia-xg6oi
    @josemejia-xg6oi Рік тому

    Its like js async await

  • @irineu333
    @irineu333 Рік тому

    Muito bom

  • @vengateshm2122
    @vengateshm2122 Рік тому +1

    It will still take two seconds even if you use async because runblocking doesn't execute them sequentially only.

  • @hardendurorider
    @hardendurorider 8 місяців тому

    fatal? no! not the best performance? yes! don't clickbait with these titles

    • @PhilippLackner
      @PhilippLackner  8 місяців тому

      Lol, if you're making 100 network calls each taking a second, we're talking about 100s vs 1s of execution time. If that isn't fatal, what is?

    • @hardendurorider
      @hardendurorider 8 місяців тому

      ​@@PhilippLackner most I did is 26 api calls in one screen :D still not fatal, haha, and if that is the case it's easy to spot the issue.
      By the time you might consider it" fatal" you're gonna realize that you are doing something wrong.
      My point being is that if you're doing 1-2-3 apoi calls sequential is not "fatal", many times you don't even realize (not saying it's ok to do them in sequence): the app will be slightly slower but you can use it. Between 100ms to 200ms is still a usable app, not fatal!

    • @nesletchimaew9209
      @nesletchimaew9209 8 місяців тому

      ​@@hardenduroriderits absolutely fatal if you're serious about performance. I cannot sleep if my code is not perfect

    • @hardendurorider
      @hardendurorider 8 місяців тому

      @@nesletchimaew9209 haha. True in absolute terms, won't complain

  • @petrushoc
    @petrushoc Рік тому +1

    awaitAll is better

  • @ahmedmohammed9395
    @ahmedmohammed9395 Рік тому

    Nice tip Phillip.
    It's truly wrong to use coroutines like this with exception to scenarios where you actually need to make a network call first before another.