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

Merge pull request #508 from cmatrixprobe/master

ch1-06:修改拼写错误
This commit is contained in:
chai2010 2020-04-30 09:52:55 +08:00 committed by GitHub
commit d6b085a92c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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
}
}