1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-23 20:02:22 +00:00

ch1-06:修改拼写错误

This commit is contained in:
cmatrixprobe 2020-04-29 15:41:30 +08:00
parent 019b4f4811
commit 42406e0ba1

View File

@ -587,14 +587,14 @@ func main() {
我们通过`close`来关闭`cancel`管道向多个Goroutine广播退出的指令。不过这个程序依然不够稳健当每个Goroutine收到退出指令退出时一般会进行一定的清理工作但是退出的清理工作并不能保证被完成因为`main`线程并没有等待各个工作Goroutine退出工作完成的机制。我们可以结合`sync.WaitGroup`来改进:
```go
func worker(wg *sync.WaitGroup, cannel chan bool) {
func worker(wg *sync.WaitGroup, cancel chan bool) {
defer wg.Done()
for {
select {
default:
fmt.Println("hello")
case <-cannel:
case <-cancel:
return
}
}