mirror of
https://github.com/juanfont/headscale.git
synced 2026-09-17 05:52:17 +09:00
all: use sync.WaitGroup.Go
Drops the Add/Done bookkeeping, which in batcher.go was spread across three functions.
This commit is contained in:
committed by
Kristoffer Dalby
parent
245b81401c
commit
373c60efe3
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user