github.com/whoyao/protocol@v0.0.0-20230519045905-2d8ace718ca5/utils/workergroup.go (about) 1 package utils 2 3 import "sync" 4 5 type WorkerGroup struct { 6 wg sync.WaitGroup 7 } 8 9 func (w *WorkerGroup) Go(fn func()) { 10 w.wg.Add(1) 11 go func() { 12 fn() 13 w.wg.Done() 14 }() 15 } 16 17 func (w *WorkerGroup) Wait() { 18 w.wg.Wait() 19 }