Buffered channel

A buffered channel is a Go channel with a fixed capacity that can temporarily store values without requiring a receiver to be ready immediately. Sending blocks when the buffer is full, while receiving blocks when the buffer is empty and the channel is still open.

Minimal example

go
updates := make(chan string, 2)
updates <- "accepted"
updates <- "assigned"
fmt.Println(<-updates)
fmt.Println(<-updates)

Learn this concept

Lesson 5.1 · Channels, select and cleanup

Used in exercises

Exercise 5.3 · Per-user WebSocket hub
Prerequisite conceptsChannels