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

remen

05/12/2018, 6:38 AM
Hi everyone! The coroutines guide shows a pattern for fan-in where the producers have shared access to a single send-channel. Is there some other idiomatic approach where the fan-in is performed by the caller instead? Is there perhaps some function
fanIn(channels: Iterable<ReceiveChannel<E>>) : ReceiveChannel<E>
?
Copy code
fun producer1(x: Int, channel: SendChannel<Int>)
fun joiningConsumer1() {
  val channel = Channel()
  producer1(1, channel)
  producer2(2, channel)
  ...
}

fun producer2(x: Int) : ReceiveChannel<Int>

fun joiningConsumer2() {
    val channel1 = producer(1)
    val channel2 = producer(2)
    
    // What goes here?
}