https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

Animesh Sahu

12/08/2019, 11:02 AM
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

octylFractal

12/08/2019, 11:04 AM
withContext
will be much more performant
a

Animesh Sahu

12/08/2019, 11:04 AM
why can you explain a bit?
o

octylFractal

12/08/2019, 11:05 AM
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

dekans

12/08/2019, 2:17 PM
async
is great for laughing several processing in parallel, then you can
await
them
g

gildor

12/09/2019, 9:31 AM
This line of code is wrong on so many different levels, I recommend you to read official guide first
CoroutineScope(context).async{}.await()
5 Views