• 并发conc github.com/sourcegraph/conc
    var wg conc.WaitGroup
     defer wg.Wait()
     startTheThing(&wg)
    func startTheThing(wg *conc.WaitGroup) {
     wg.Go(func() {
         fmt.Println(1)
     })
    }
    原声写法
    var wg sync.WaitGroup
     for i := 0; i < 10; i++ {
         wg.Add(1)
         go func() {
             defer wg.Done()
             doSomething()
         }()
     }
     wg.Wait()
    conc写法
    var wg conc.WaitGroup
     for i := 0; i < 10; i++ {
         wg.Go(doSomething)
     }
     wg.Wait()
文档更新时间: 2024-10-21 01:07   作者:Yoby