ursus
04/06/2026, 10:20 PM*receiveAsFlow*: This function allows the resulting flow to have *multiple collectors*. However, each element emitted from the channel will only be delivered to *one* of the collectors (fan-out fashion).
which one? last? nondeterministic race?
also whats fan out in this context? never heard it used to mean one of manyZach Klippenstein (he/him) [MOD]
04/06/2026, 10:25 PMursus
04/06/2026, 10:29 PMZach Klippenstein (he/him) [MOD]
04/06/2026, 10:30 PMsounds like a footgun waiting to happenThat's why it's called out in the docs
ursus
04/06/2026, 10:45 PMZach Klippenstein (he/him) [MOD]
04/06/2026, 10:51 PMIan Lake
04/07/2026, 12:08 AMSaurav Suman
04/28/2026, 9:25 AMimport kotlinx.coroutines.launch
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
fun main() {
val scope = CoroutineScope(Dispatchers.Default)
val numbers = Channel<Int>()
val producer = scope.launch {
numbers.send(1)
numbers.send(2)
numbers.send(3)
numbers.send(4)
numbers.close()
}
val consumer = scope.launch {
for(num in numbers) {
println("________ consumer1: ${num}")
}
}
val consumer2 = scope.launch {
for(num in numbers) {
println("________ consumer2: ${num}")
}
}
runBlocking {
producer.join()
consumer.join()
consumer2.join()
}
}
You'll get different outputs every time:
1st Run:
________ consumer1: 1
________ consumer1: 2
________ consumer1: 3
________ consumer2: 4
2nd Run:
________ consumer2: 2
________ consumer2: 3
________ consumer1: 1
________ consumer2: 4
3rd Run:
________ consumer1: 1
________ consumer2: 3
________ consumer2: 4
________ consumer1: 2
Please try this:
If there are any suggestions or inputs from anyone, please let me know.ursus
04/28/2026, 9:38 AMSaurav Suman
04/28/2026, 3:04 PM