https://kotlinlang.org logo
Title
t

thevery

09/29/2018, 10:55 PM
With new SC, is there any changes in
withContext
vs
async
policy or it is ok to continue using
withContext
?
CoroutineScope
sample uses
async
, not `withContext`: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-coroutine-scope/index.html
g

gildor

09/30/2018, 11:38 AM
I think withContext is still more idiomatic and optimal solution
t

thevery

09/30/2018, 11:55 AM
It is not quite clear how withContext is connected with parent scope - async and launch are directly tied to scope but withContext is not
k

kingsley

09/30/2018, 12:27 PM
I believe
withContext
is also very much a member of the scope. And very much like
coroutineScope
, it suspends until it’s execution is complete, which as Andrey said, it more optimal than calling eager
async {}.await()
in the same scope
g

gildor

09/30/2018, 12:54 PM
withContext is also coroutine scope and also tied to parent scope
e

elizarov

09/30/2018, 1:25 PM
You should use async only when you need parallelism.
👌 1