🐦 Kotlin
Advanced
What is a Channel in Kotlin coroutines?
Answer
A Channel is a concurrent primitive for communication between coroutines — like a blocking queue but with suspend functions instead of blocking calls. One coroutine send()s values (suspending if the buffer is full), and another receive()s them (suspending if the channel is empty). Channels are hot and stateful. Types: Rendezvous (no buffer — sender suspends until receiver is ready), Buffered (fixed-size buffer), Unlimited, and Conflated (only keeps the latest value). For most use cases, SharedFlow is a better choice as it is broadcast-capable and does not need to be explicitly closed.