Marc Knaup
12/13/2018, 4:03 PMReceiveChannel
from an Iterable
?
à la
fun <E> Iterable<E>.toChannel() =
GlobalScope.produce { forEach { send(it) } }
mbonnet
12/13/2018, 4:30 PMfun <T> Iterable<T>.toChannel(): ReceiveChannel<T> {
val channel = Channel<T>(Channel.UNLIMITED)
GlobalScope.launch {
this@toChannel.forEach { channel.send(it) }
channel.close()
}
return channel
}
I only tested it on a quick example, seems to work ok !Marc Knaup
12/13/2018, 4:39 PMDico
12/13/2018, 5:20 PMproduce
might use a different type of channel. Other than that, produce vs. launch.