mingkangpan
12/04/2018, 12:10 PMfun main() {
runBlocking {
val foo1 = withContext(IO) {
delay(100)
"foo1"
}
val fooDeferred = async(IO) {
delay(100)
"foo2"
}
val foo2 = fooDeferred.await()
print("$foo1 and $foo2")
}
}
^ can someone tell me, what the different here between async(IO)
and withContext(IO)
?
only that async is deferred?Dominaezzz
12/04/2018, 12:14 PMwithContext
as an optimization, for when you immediately await an async.withContext
is used when you want to switch contexts but not create a new coroutine.zokipirlo
12/04/2018, 12:51 PMgildor
12/04/2018, 1:53 PMDominaezzz
12/04/2018, 1:55 PM