Puzzle 16 Explanation: Channel Capacity
Understand how channels work in Go.
We'll cover the following...
We'll cover the following...
Try it yourself
Try executing the code below to see the result.
Go (1.16.5)
package mainimport ("fmt")func main() {ch := make(chan int, 2)ch <- 1ch <- 2<-chclose(ch)a := <-chb := <-chfmt.Println(a, b)}
Explanation
The ch
channel is a buffered channel with a capacity of 2
(we can check this ...