Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
go example of blocking buffered channels in go
package main
import "fmt"
import "time"
func write(channel chan int) {
for i := 0; i < 5; i++ {
channel <- i
fmt.Println("successfully wrote", i, "to channel")
func main() {
ch := make(chan int, 2)
go write(ch)
time.Sleep(2 * time.Second)
for v := range ch {
fmt.Println("read value", v, "from channel")
time.Sleep(2 * time.Second)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.