chs := make(chan int64, 3) wg := sync.WaitGroup{} var i int64 for i = 0; i < 3; i++ { wg.Add(1) chs <- i } t1 := time.Now().Unix() go func() { time.Sleep(time.Second * 4) fmt.Println(<-chs) wg.Done() }() go func() { time.Sleep(time.Second * 1) fmt.Println(<-chs) wg.Done() }() go func() { time.Sleep(time.Second * 2) fmt.Println(<-chs) wg.Done() }() wg.Wait() t2 := time.Now().Unix() fmt.Println("总耗时", t2-t1)
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production. - using env: export GIN_MODE=release - using code: gin.SetMode(gin.ReleaseMode) [GIN-debug] GET /hello --> main.Hello (3 handlers) [GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value. Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details. [GIN-debug] Listening and serving HTTP on :88 0 1 2 总耗时 4 [GIN] 2022/12/10 - 16:46:16 | 200 | 4.001959301s | 192.168.133.1 | GET "/hello"
总耗时以时间最长的为准