voddan
10/07/2018, 6:28 PMval hotStream: ReceiveChannel<Int> = produce<Int> {
var i = 0
while (true) {
i += 1
println("hot-create item #$i")
send(i)
}
}
// Usage:
val next = hotStream.receive()
Do I understand that correctly that hotStream in this snippet is a hot stream because it produces the elements regardless if we consume them or not, and coldStream below is a cold stream because it calculates the elements only after they are requested?
val coldStream: ReceiveChannel<Deferred<Int>> = produce<Deferred<Int>> {
var i = 0
while (true) {
val item = async(start = CoroutineStart.LAZY) {
i += 1
println("cold-create item #$i")
i
}
send(item)
}
}
// Usage:
val next = coldStream.receive().await()