Different Kinds of Channels in Kotlin
Overview of the different kinds of Kotlin channels and their behaviors.
In Rendezvous channels capacity is 0. Which means the channel has no buffer at all. Elements are transferred only when sender and receiver meet. Which is literally what Rendezvous means. I like to picture it as a relay race where the runners need to meet at one point to pass the baton.
In technical terms this means that
send suspends until another coroutine invokes
receive suspends until another coroutine invokes
Buffered channels have a positive capacity but are not
send suspends only if the buffer is full. And calling
receive suspends only if buffer is empty (i.e. there are no more messages in the channel).
You guessed it. Unlimited buffer. Sender will never suspend on
But there’s no such thing as Unlimited, right? The implementation uses a linked-list buffer so your only constraint is memory.
This is the oddball. The sender never suspends, but the channel offers at most one element at any given time. When a new element comes, the previous element in the channel (if any) is discarded. The receiver only gets the most recent element sent. Previous elements are lost.