July 2018
Intermediate to advanced
266 pages
7h 11m
English
There is a third type of buffered channel, based on the idea that it's fine if elements that were emitted are lost. This means that this type of channel has a buffer of only one element, and whenever a new element is sent, the previous one will be lost. This also means that the sender will never be suspended.
You can instantiate it by calling its constructor:
val channel = ConflatedChannel<Int>()
You can also do so by calling the Channel() function with the parameter Channel.CONFLATED:
val channel = Channel<Int>(Channel.CONFLATED)
This channel will never suspend a sender. Instead, it will override the elements that were not retrieved. Consider this example:
fun main(args: Array<String>) = runBlocking { val time = measureTimeMillis ...
Read now
Unlock full access