groostav
07/18/2017, 12:19 AMBroadcastChannel
, how might I get it?
eg:
val bufferedBroadcastChannel = bufferedBroadcastChannel<Int>();
launch(UI) { dispatchToStdOut(bufferedBroadcastChannel) }
bufferedBroadcastChannel.send(1)
launch(CommonPool) { dispatchToFile(bufferedBroadcastChannel) }
bufferedBroadcastChannel.send(2)
//...
fun dispatchToStdOut(channel: Channel<Int>){
channel.consumeEach {
println(it)
}
}
fun dispatchToFile(channel: Channel<Int>){
channel.consumeEach {
file.writeLine(it)
}
}
which outputs
1
2
and also puts that in a file