refactor(concurrency): simplify some waitgroup usage, remove extra wg.Done in wg.Go left in 11af9d1 in io.go

This commit is contained in:
yusing
2025-08-17 00:23:54 +08:00
parent b32750d545
commit 0862920324
5 changed files with 4 additions and 13 deletions

View File

@@ -23,9 +23,7 @@ import (
func parallel(fns ...func()) {
var wg sync.WaitGroup
for _, fn := range fns {
wg.Go(func() {
fn()
})
wg.Go(fn)
}
wg.Wait()
}

View File

@@ -82,12 +82,10 @@ func TestConcurrentAccessLoggerLogAndFlush(t *testing.T) {
func parallelLog(logger *AccessLogger, req *http.Request, resp *http.Response, n int) {
var wg sync.WaitGroup
wg.Add(n)
for range n {
go func() {
defer wg.Done()
wg.Go(func() {
logger.Log(req, resp)
}()
})
}
wg.Wait()
}

View File

@@ -128,7 +128,6 @@ func TestFinishMultipleCalls(t *testing.T) {
task := testTask()
var wg sync.WaitGroup
n := 20
wg.Add(n)
for range n {
wg.Go(func() {
task.Finish(nil)

View File

@@ -95,11 +95,9 @@ func (p BidirectionalPipe) Start() error {
var srcErr, dstErr error
wg.Go(func() {
srcErr = p.pSrcDst.Start()
wg.Done()
})
wg.Go(func() {
dstErr = p.pDstSrc.Start()
wg.Done()
})
wg.Wait()
return errors.Join(srcErr, dstErr)

View File

@@ -15,9 +15,7 @@ func TestRefCounterAddSub(t *testing.T) {
rc.Add()
for range 2 {
wg.Go(func() {
rc.Sub()
})
wg.Go(rc.Sub)
}
wg.Wait()