mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:06:41 +08:00
24 lines
231 B
Go
Executable File
24 lines
231 B
Go
Executable File
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func main() {
|
|
c := make(chan int)
|
|
// consumer:
|
|
go func() {
|
|
for {
|
|
fmt.Print(<-c, " ")
|
|
}
|
|
}()
|
|
// producer:
|
|
for {
|
|
select {
|
|
case c <- 0:
|
|
case c <- 1:
|
|
}
|
|
}
|
|
|
|
}
|