More goofing around with buffered channels

This commit is contained in:
Dan Buch 2012-11-07 00:34:24 -05:00
parent 6e17df80ab
commit 19b17354e0

View File

@ -1,11 +1,29 @@
package main package main
import "fmt" import (
"fmt"
"time"
)
func main() { func main() {
c := make(chan int, 2) c := make(chan int, 2)
c <- 1 q := make(chan bool)
c <- 2
fmt.Println(<-c) go func(c chan int) {
fmt.Println(<-c) for i := range c {
fmt.Println("\t", i, "<- popped")
time.Sleep(300 * time.Millisecond)
}
}(c)
go func(c chan int) {
i := 0
for {
c <- i
fmt.Println("pushed ->", i)
i += 1
}
}(c)
<-q
} }