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

ivan.savytskyi

02/25/2019, 8:13 PM
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

bdawg.io

02/25/2019, 8:38 PM
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

ivan.savytskyi

02/25/2019, 8:39 PM
Oh nice thx!!!!
e

elizarov

02/25/2019, 9:05 PM
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

efemoney

02/27/2019, 1:01 PM
That is amazing
3 Views