Avoid THIS Fatal Coroutine Mistake in Kotlin

Avoid THIS Fatal Coroutine Mistake in Kotlin

Philipp Lackner

1 год назад

33,104 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Libin Mathew
Libin Mathew - 20.06.2023 17:59

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.

Ответить
Vengatesh M
Vengatesh M - 20.06.2023 11:32

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

Ответить
Dhruv Sharma
Dhruv Sharma - 27.04.2023 08:32

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

Ответить
benjamin1313
benjamin1313 - 24.03.2023 10:54

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

Ответить
Irineu A. Silva
Irineu A. Silva - 29.01.2023 17:14

Muito bom

Ответить
AYOUB MAZROU
AYOUB MAZROU - 28.01.2023 11:13

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

Ответить
Syd Narrett
Syd Narrett - 22.01.2023 18:38

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

Ответить
jose mejia
jose mejia - 10.01.2023 01:39

Its like js async await

Ответить
Sushil Kafle
Sushil Kafle - 05.01.2023 17:22

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

Ответить
Leonardo Luna Ruiz
Leonardo Luna Ruiz - 05.01.2023 16:25

This would be necessary when I use retrofit network calls?

Ответить
Víctor Manuel Hernández
Víctor Manuel Hernández - 05.01.2023 09:08

Very nice 👍

Ответить
Jaidyn Belbin
Jaidyn Belbin - 05.01.2023 03:18

Just like async let in Swift. Nice little video 🙂

Ответить
shlusiak
shlusiak - 05.01.2023 00:50

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

Ответить
Petrus Nguyễn Thái Học
Petrus Nguyễn Thái Học - 04.01.2023 20:54

awaitAll is better

Ответить
Ahmed Mohammed
Ahmed Mohammed - 04.01.2023 18:38

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.

Ответить
Azizbek Rasulmetov
Azizbek Rasulmetov - 04.01.2023 18:21

The point here is to launch coroutine separately to achieve concurrency

Ответить
Azizbek Rasulmetov
Azizbek Rasulmetov - 04.01.2023 18:20

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

Ответить
Angelo Marzocchi
Angelo Marzocchi - 04.01.2023 17:38

This man is the goat

Ответить
RinoSss
RinoSss - 04.01.2023 17:10

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

Ответить
AApip CPS
AApip CPS - 04.01.2023 16:31

this help me to understanding coroutine, thanks

Ответить
Ruavaen
Ruavaen - 04.01.2023 16:11

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

Ответить