Probably has already been asked. Shouldn’t be alwa...
# coroutines
d
Probably has already been asked. Shouldn’t be always preferred to use withContext() instead of launch() ?
v
they are doing different things basically, so one cannot be preferred over another. But if you end up asking yourself what should you use in this particular place of code, it’s probably
withContext
🙂
g
Or just nothing and use suspend functions without context and dispatcher switching
d
@gildor Do you mean use suspend function without launch a new coroutine? Shouldn’t be like calling a normal function in the same thread ?
g
Yes, suspend function without creating new coroutines It highly depends what you do in this suspend function. If you calling another suspend functions, than this is perfect solution, no need to start new coroutines If you have blocking code (blocking io or cpu bound tasks) than wrap it to withContext with corresponding dispatcher
Use launch only top most level to start coroutines, or if you want to do something in parallel (or async if you do something in parallel and you need result)