Does anyone have any suggestions on how to create ...
# coroutines
b
Does anyone have any suggestions on how to create a coroutine that tracks the completion of other jobs before launching a final coroutine? ie, I have two jobs that are running: Job A, Job B I have a third job, that must wait for A and B to finish: Job C
Copy code
/ -- [ Job A ] -- \
----                  ---- [ Job C ]
    \ -- [ Job B ] -- /
d
simple
.join()
on A and B, no?
e
Copy code
val a = launch { doJobA() }
val b = launch { doJobB() }
launch { 
    a.join()
    b.join()
    doJobC()
}
­čĹŹ 1
b
Sweet, I think I might try to use this launch variant
Copy code
fun launchOnComplete(
    vararg jobs: Job,
    context: CoroutineContext = DefaultDispatcher,
    start: CoroutineStart = CoroutineStart.DEFAULT,
    parent: Job? = null,
    block: suspend CoroutineScope.() -> Unit
) = launch {
    jobs.forEach { it.join() }
    launch(context, start, parent, block).join()
}
d
There's such a plenty of top level / extension functions. There must be an extension to join an
Interable
of `Job`s
d
@elizarov don't you think that so much number of top level declarations is a problem?
i'm talking about those like in
ThreadPoolDispatcher.kt
e
Do you find any practical problems with them?
d
well, it feels like pressure a bit, you have to know about them and they are wasting the global autocompletion space
Using coroutines forces
autocompletion-driven-development
anyway=)