is it thread safe to iterate over job’s children `...
# coroutines
i
is it thread safe to iterate over job’s children
job.children.toList()
? By looking into source seems should be fine, but want to confirm
b
All functions on this interface and on all interfaces derived from it are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.
https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/
You should be fine to do so
i
Oh nice thx!!!!
e
Pro tip: You can iterate a children sequence as is live, without doing
toList()
. New children launched while you iterate are added to the end, so
job.children.forEach { it.await() }
actually waits for all children, even when some children launch new children.
☝️ 2
👍 3
e
That is amazing