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

elizarov

11/29/2017, 10:20 AM
You don’t need to explicitly do
join
if you rely on parent/child rels to split one large task into parallel subtasks. So, to do
mySuspendingTask
100 times in parallel you can just do:
Copy code
fun main(args: Array<String>) = runBlocking {
    (0..100).forEach { launch(coroutineContext) { mySuspendingTask() } }
}
Now you are explicit about parallelism — you’ll launched concurrent subtask. No worries, since they are very cheap. You can run millions. You outer job (in this case — main) automatically waits for all the children to complete.
g

gildor

11/29/2017, 10:21 AM
Yes, but only if you don’t want to use result of mySuspendingTask() or run something after those tasks finished
2 Views