github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume1/section4/bufferedchannel/bufferedchannel.go (about) 1 // An example of a buffered channel (asynchronous). 2 package main 3 4 import "fmt" 5 6 func main() { 7 8 // We create a buffered channel of strings with a capacity of 3 9 // This means the channel buffer can hold up to 3 values 10 messageQueue := make(chan string, 3) 11 messageQueue <- "one" 12 messageQueue <- "two" 13 messageQueue <- "three" 14 15 // We drain the messageQueue by receiving all the values from the 16 // buffered channel. 17 fmt.Println(<-messageQueue) 18 fmt.Println(<-messageQueue) 19 fmt.Println(<-messageQueue) 20 21 }