diff --git a/gotime/src/meatballhat.com/gotour-artifacts/buffered-channels/main.go b/gotime/src/meatballhat.com/gotour-artifacts/buffered-channels/main.go index c47b4ae..9873435 100644 --- a/gotime/src/meatballhat.com/gotour-artifacts/buffered-channels/main.go +++ b/gotime/src/meatballhat.com/gotour-artifacts/buffered-channels/main.go @@ -1,11 +1,29 @@ package main -import "fmt" +import ( + "fmt" + "time" +) func main() { c := make(chan int, 2) - c <- 1 - c <- 2 - fmt.Println(<-c) - fmt.Println(<-c) + q := make(chan bool) + + go func(c chan int) { + 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 }