SUPERCILEX
10/19/2018, 7:44 AMjoin
now that the outer scope will wait for all functions launched within to complete?elizarov
10/19/2018, 7:44 AMelizarov
10/19/2018, 7:45 AMval subTask = launch { doSomething() }
// do something else in parallel
subTask.join()
// continue only when subTask completes
// do more stuff
elizarov
10/19/2018, 7:45 AMSUPERCILEX
10/19/2018, 7:47 AMSUPERCILEX
10/19/2018, 7:47 AMwithContext
at that point?elizarov
10/19/2018, 7:51 AMelizarov
10/19/2018, 7:52 AMcoroutineContext
to the same effect:
coroutineContext {
launch { doSomething() }
// do something else in parallel
}
// continue only when subTask completes
// do more stuff
But that is more nesting in codeSUPERCILEX
10/19/2018, 7:54 AMSUPERCILEX
10/19/2018, 7:56 AMSUPERCILEX
10/19/2018, 7:57 AMSUPERCILEX
10/19/2018, 7:57 AMSUPERCILEX
10/19/2018, 7:58 AMval subTask = async { doSomething() }
val sub2 = async { ... }
awaitAll(subTask, sub2)
// do more stuff
SUPERCILEX
10/19/2018, 7:59 AMlaunch
just needs to do some background with and we don't care about a result?elizarov
10/19/2018, 8:00 AMlaunch
if you need side-effect of some work (like store stuff to DB). You use async if you need result of some work.SUPERCILEX
10/19/2018, 8:02 AMSUPERCILEX
10/19/2018, 8:03 AM