buffered channel
A channel created with a capacity, such as make(chan int, 2), that can hold that many values before a send has to wait.
In more detail
An unbuffered channel has no space, so every send waits for a receiver. A buffer lets a sender run ahead by a bounded amount, which is useful for a results channel sized to the number of workers or a signal channel of size one. Size it deliberately rather than to hide a design problem.
Example
results := make(chan string, 2)Related terms
- channel — A typed pipe in Go that one goroutine sends values into and another receives them from, safely handing data between them.
- make (built-in) — The built-in Go function that creates a ready-to-use map, slice or channel, such as make(map[string]bool) or make(chan string).
- blocking operation — An operation that makes the code wait until something happens, such as a receive waiting for a value to arrive on a channel.
Taught in
- Channels and Synchronization — Concurrent Systems Programming with Go
- The select Statement — Concurrent Systems Programming with Go
- Graceful Shutdown on SIGTERM — Concurrent Systems Programming with Go
- Executing Concurrent Checks — Concurrent Systems Programming with Go