How do CoroutineScope() class works? what happens ...
# coroutines
a
How do CoroutineScope() class works? what happens if you create multiple scopes on single context? and what's better
CoroutineScope(context).async{}.await()
or
withContext(context) {}
?
o
withContext
will be much more performant
a
why can you explain a bit?
o
CoroutineScope
is literally just a container for a context with extension functions for creating child jobs, creating multiple for a single context is weird but it shouldn't really affect anything
withContext
has some optimizations such as not dispatching if the new context doesn't change dispatcher, or not suspending / making changes if the context is the exact same
additionally,
withContext
doesn't start a new sub-Job, and is properly bound to the current Job lifecycle
d
async
is great for laughing several processing in parallel, then you can
await
them
g
This line of code is wrong on so many different levels, I recommend you to read official guide first
CoroutineScope(context).async{}.await()