Yes, looks like it :slightly_smiling_face: The bea...
# coroutines
u
Yes, looks like it 🙂 The beauty of coroutines is, that you have a sequential flow, even with suspension points.
m
Hi again 🙂 Sorry to disturb you again. https://proandroiddev.com/android-coroutine-recipes-33467a4302e9 The article have two examples.
execute two tasks sequentially
and
execute two tasks parallel
. But I don't get the difference. Aren't both examples executed in parallel?
u
Nope, the difference is in the await
Task1 is awaited right where it is created. So the coroutine suspends and does not yet schedule Task2
Only after Task1 finishes, does the execution continue to fire Task2 to the background
So both examples run the tasks in the background. But the sequential example will only schedule one Task to the background at a time
m
But my first example do the same thing.
fetchImagesAndSpaces()
does the same as the sequential example. Doesn't it? 🤔
u
No, you are doing as in the second example. You only await, after both Tasks are created: async, await async, await Compared to: async async await await
m
Aha! I get it now. Thanks again 😄