[Golang]妙用channel

abv123456789 ·
polaris
社区,需要你我一同完善!
已修复
#2
更多评论
代码怎么搞的?完全没法看
#1
```go package main import ( "fmt" "time" ) func producer(c chan int64, max int) { defer close(c) for i := 0; i < max; i++ { c <- time.Now().Unix() } } func consumer(c chan int64) { var v int64 ok := true for ok { if v, ok = <-c; ok { fmt.Println(v) } } } func main() { c := make(chan int64) go producer(c, 10000) consumer(c) } ```
#3