Channel buffering
Context
Section titled “Context”Buffered channels have a capacity. Sends to a buffered channel block only when the buffer is full; receives block when the buffer is empty. Use make(chan T, capacity).
Example
Section titled “Example”Send three values to a buffered channel without an immediate receiver.
Code example
Section titled “Code example”package main
import "fmt"
func main() { ch := make(chan string, 2) ch <- "buffered" ch <- "channel" fmt.Println(<-ch) fmt.Println(<-ch)}Output
Section titled “Output”bufferedchannel