Go 中 defer 会不会等待 goroutinue ,小例子
package main import ( "fmt" "sync" ) func main() { defer func() { fmt.Println("defer") }() var wg sync.WaitGroup wg.Add(1) go func(wg *sync.WaitGroup) { defer wg.Done() //time.Sleep(1000000) fmt.Println("gogoggogogo") }(&wg) wg.Wait() } 结果: gogoggogogo defer
邮箱: 1090055252@qq.com