Channel Types: Rendezvous, Buffered, Conflated, Unlimited
Choose the right channel type for your communication pattern.
Channel Factory
Create channels with Channel<T>(capacity). The capacity determines buffering and suspension behavior.
import kotlinx.coroutines.channels.Channel
val rendezvous = Channel<Int>() // capacity 0
val buffered = Channel<Int>(64) // capacity 64
val unlimited = Channel<Int>(Channel.UNLIMITED)
val conflated = Channel<Int>(Channel.CONFLATED)
fun main() { println("Channel types created") }Rendezvous Channel (capacity=0)
Default channel. send suspends until a receiver is ready, and receive suspends until a sender sends. They rendezvous — meet at the same point.
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
fun main() = runBlocking {
val ch = Channel<Int>() // rendezvous
launch {
println("Sending...")
ch.send(1) // suspends until receiver is ready
println("Sent")
}
delay(100)
println("Receiving...")
println(ch.receive())
}All lessons in this course
- Channel Basics: send, receive, and close
- Channel Types: Rendezvous, Buffered, Conflated, Unlimited
- Mutex and Semaphore for Shared State
- Actors and Structured State Management