Комментарии:
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.
ОтветитьIt will still take two seconds even if you use async because runblocking doesn't execute them sequentially only.
ОтветитьWithout asyn it will come in single coroutine where as using async it will make both calls parallel.
ОтветитьJust gotten into learning about coroutines. Thanks for the great tip.
ОтветитьMuito bom
ОтветитьI was making 2 blocks of launch {} for each function . To run it in parallel
Ответитьasync-await is to decompose a task into potentially multiple running subtasks, right? so how this can be used to run independent tasks?
ОтветитьIts like js async await
ОтветитьWoww... this made the concept crystal clear... hats off 👏 🙌
ОтветитьThis would be necessary when I use retrofit network calls?
ОтветитьVery nice 👍
ОтветитьJust like async let in Swift. Nice little video 🙂
ОтветитьFrom "Fatal mistake" to "mistake" to "performance tip"... Bit sensational title, no?
ОтветитьawaitAll is better
Ответить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.
The point here is to launch coroutine separately to achieve concurrency
ОтветитьWe can achieve it with launch as well if it doesn't return anything!
ОтветитьThis man is the goat
Ответить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
this help me to understanding coroutine, thanks
Ответить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
Ответить