mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 04:48:29 +08:00
update book code
This commit is contained in:
22
eBook/exercises/chapter_14/goroutine_panic.go
Executable file
22
eBook/exercises/chapter_14/goroutine_panic.go
Executable file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func tel(ch chan int) {
|
||||
for i := 0; i < 15; i++ {
|
||||
ch <- i
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
var ok = true
|
||||
ch := make(chan int)
|
||||
|
||||
go tel(ch)
|
||||
for ok {
|
||||
i := <-ch
|
||||
fmt.Printf("ok is %t and the counter is at %d\n", ok, i)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user