all: use sync.WaitGroup.Go

Drops the Add/Done bookkeeping, which in batcher.go was spread across
three functions.
This commit is contained in:
Kristoffer Dalby
2026-08-25 09:43:47 +00:00
committed by Kristoffer Dalby
parent 245b81401c
commit 373c60efe3
9 changed files with 46 additions and 106 deletions
+2 -10
View File
@@ -403,9 +403,7 @@ func (b *Batcher) Start() {
return
}
b.wg.Add(1)
go b.doWork()
b.wg.Go(b.doWork)
}
func (b *Batcher) Close() {
@@ -439,12 +437,8 @@ func (b *Batcher) Close() {
}
func (b *Batcher) doWork() {
defer b.wg.Done()
for i := range b.workers {
b.wg.Add(1)
go b.worker(i + 1)
b.wg.Go(func() { b.worker(i + 1) })
}
// Create a cleanup ticker for removing truly disconnected nodes
@@ -467,8 +461,6 @@ func (b *Batcher) doWork() {
}
func (b *Batcher) worker(workerID int) {
defer b.wg.Done()
wlog := log.With().Int(zf.WorkerID, workerID).Logger()
for {
+4 -7
View File
@@ -142,19 +142,16 @@ func runConcurrently(t *testing.T, n int, fn func(i int)) int {
)
for i := range n {
wg.Add(1)
go func(idx int) {
defer wg.Done()
wg.Go(func() {
defer func() {
if r := recover(); r != nil {
panics.Add(1)
t.Logf("panic in goroutine %d: %v", idx, r)
t.Logf("panic in goroutine %d: %v", i, r)
}
}()
fn(idx)
}(i)
fn(i)
})
}
wg.Wait()