dave08
10/25/2018, 5:43 PMimport kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.actor
import kotlinx.coroutines.experimental.channels.consumeEach
import kotlinx.coroutines.experimental.runBlocking
import kotlinx.coroutines.experimental.*
fun main(args: Array<String>) = runBlocking {
val progressNotifier = actor<Long>(<http://Dispatchers.IO|Dispatchers.IO>) {
consumeEach {
println(it.toString())
}
}
val progressMapper = actor<Int>(<http://Dispatchers.IO|Dispatchers.IO>) {
for (it in channel) {
progressNotifier.offer(it.toLong())
}
}
(0..5).forEach {
progressMapper.offer(it)
}
progressMapper.close()
}
Alexander
10/25/2018, 5:58 PMdave08
10/25/2018, 5:59 PMdave08
10/25/2018, 6:01 PMfun main(args: Array<String>) = runBlocking {
println("set up #1")
val progressNotifier = actor<Long>(<http://Dispatchers.IO|Dispatchers.IO>, Channel.CONFLATED) {
consumeEach {
println(it.toString())
}
}
println("set up #2")
val progressMapper = actor<Int>(<http://Dispatchers.IO|Dispatchers.IO>, Channel.CONFLATED) {
consumeEach {
progressNotifier.offer(it.toLong())
}
}
(0..5).forEach {
println("sending $it")
progressMapper.offer(it)
}
progressMapper.close()
}
Alexander
10/25/2018, 6:03 PMdave08
10/25/2018, 6:04 PM