go 关闭chan 广播信号
package main import ( "fmt" "sync" ) func hello(num ...int) { num[0] = 18 } func main() { closeChan := make(chan struct{}) wg := &sync.WaitGroup{} for i := 0; i < 10; i++ { wg.Add(1) go func(i int) { defer func() { wg.Done() }() <-closeChan fmt.Println(i, "closed") }(i) } close(closeChan) //广播关闭 wg.Wait() }