By default channels are unbuffered, meaning that they
will only accept sends ( |
|
package main
|
|
import "fmt"
|
|
func main() {
|
|
Here we |
messages := make(chan string, 2)
|
Because this channel is buffered, we can send these values into the channel without a corresponding concurrent receive. |
messages <- "buffered"
messages <- "channel"
|
Later we can receive these two values as usual. |
fmt.Println(<-messages)
fmt.Println(<-messages)
}
|
$ go run channel-buffering.go
buffered
channel
|
Next example: Channel Synchronization.