CONFLATED

const val CONFLATED: Int(source)

A single-element buffer with conflating behavior.

Specifying CONFLATED as the capacity in the Channel(...) factory function is equivalent to creating a channel with a buffer of size 1 and a BufferOverflow strategy of BufferOverflow.DROP_OLDEST: Channel(1, onBufferOverflow = BufferOverflow.DROP_OLDEST). Such a channel buffers at most one element and conflates all subsequent send and trySend invocations so that the receiver always gets the last element sent, losing the previously sent elements: see the "Undelivered elements" section in the Channel documentation. Sending to this channel never suspends, and trySend always succeeds.

val channel = Channel<Int>(Channel.CONFLATED)
channel.send(1)
channel.send(2)
channel.send(3)
check(channel.receive() == 3)

Specifying a BufferOverflow other than BufferOverflow.SUSPEND is not allowed with CONFLATED, and an IllegalArgumentException is thrown if such a combination is used. For creating a conflated channel that instead keeps the existing element in the channel and throws out the new one, use Channel(1, onBufferOverflow = BufferOverflow.DROP_LATEST).