RENDEZVOUS

const val RENDEZVOUS: Int = 0(source)

The zero buffer capacity.

For the default BufferOverflow value of BufferOverflow.SUSPEND, Channel(RENDEZVOUS) creates a channel without a buffer. An element is transferred from the sender to the receiver only when send and receive invocations meet in time (that is, they rendezvous), so send suspends until another coroutine invokes receive, and receive suspends until another coroutine invokes send.

val channel = Channel<Int>(Channel.RENDEZVOUS)
check(channel.trySend(5).isFailure) // sending fails: no receiver is waiting
launch(start = CoroutineStart.UNDISPATCHED) {
val element = channel.receive() // suspends
check(element == 3)
}
check(channel.trySend(3).isSuccess) // sending succeeds: receiver is waiting

If a different BufferOverflow is specified, Channel(RENDEZVOUS) creates a channel with a buffer of size 1:

val channel = Channel<Int>(0, onBufferOverflow = BufferOverflow.DROP_OLDEST)
// None of the calls suspend, since the buffer overflow strategy is not SUSPEND
channel.send(1)
channel.send(2)
channel.send(3)
check(channel.receive() == 3)