dimsuz
12/08/2021, 2:46 PMFlow.collectIndexed and it's implemented like this:
collect(object : FlowCollector<T> {
private var index = 0
override suspend fun emit(value: T) = action(checkIndexOverflow(index++), value)
})
I'm curious, why is this thread-safe? Can't it happen so that index is initialized on one thread and incremented in another? (if some withContext will somehow be used by client)
Or are there some invariants which are at play here?louiscad
12/08/2021, 4:29 PMdimsuz
12/08/2021, 4:42 PM