2012-11-07 05:16:13 +00:00
|
|
|
package main
|
|
|
|
|
2012-11-07 05:34:24 +00:00
|
|
|
import (
|
2012-11-10 18:41:33 +00:00
|
|
|
"fmt"
|
|
|
|
"time"
|
2012-11-07 05:34:24 +00:00
|
|
|
)
|
2012-11-07 05:16:13 +00:00
|
|
|
|
|
|
|
func main() {
|
2012-11-10 18:41:33 +00:00
|
|
|
c := make(chan int, 2)
|
|
|
|
q := make(chan bool)
|
2012-11-07 05:34:24 +00:00
|
|
|
|
2012-11-10 18:41:33 +00:00
|
|
|
go func(c chan int) {
|
|
|
|
for i := range c {
|
|
|
|
fmt.Println("\t", i, "<- popped")
|
|
|
|
time.Sleep(300 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}(c)
|
2012-11-07 05:34:24 +00:00
|
|
|
|
2012-11-10 18:41:33 +00:00
|
|
|
go func(c chan int) {
|
|
|
|
i := 0
|
|
|
|
for {
|
|
|
|
c <- i
|
|
|
|
fmt.Println("pushed ->", i)
|
|
|
|
i += 1
|
|
|
|
}
|
|
|
|
}(c)
|
2012-11-07 05:34:24 +00:00
|
|
|
|
2012-11-10 18:41:33 +00:00
|
|
|
<-q
|
2012-11-07 05:16:13 +00:00
|
|
|
}
|