🐹 Go (Golang)
Intermediate
What are buffered channels and when are they useful?
Answer
A buffered channel has an internal queue of a fixed capacity: ch := make(chan int, 10). A send to a buffered channel only blocks when the buffer is full, and a receive only blocks when the buffer is empty. This decouples the sender and receiver, allowing bursts of messages to be queued without requiring a receiver to be immediately ready. Common use cases: worker pools where jobs are queued for a fixed number of workers, rate limiting, and semaphore patterns. The built-in len(ch) returns the current number of queued items and cap(ch) returns the capacity.