mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-11-13 17:36:12 +08:00
update book code
This commit is contained in:
25
eBook/examples/chapter_14/channel_block2.go
Normal file
25
eBook/examples/chapter_14/channel_block2.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ch1 := make(chan int)
|
||||
go pump(ch1)
|
||||
go suck(ch1) // tons of numbers appear
|
||||
time.Sleep(1e9)
|
||||
}
|
||||
|
||||
func pump(ch chan int) {
|
||||
for i := 0; ; i++ {
|
||||
ch <- i
|
||||
}
|
||||
}
|
||||
|
||||
func suck(ch chan int) {
|
||||
for {
|
||||
fmt.Println(<-ch)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user