chore: use wg.Go instead of add

This commit is contained in:
Florian Schade
2026-04-22 14:07:06 +02:00
committed by Ralf Haferkamp
parent a8fff7e4c3
commit 86d79430a3
7 changed files with 18 additions and 36 deletions

View File

@@ -75,25 +75,20 @@ func (dp *DataProvider) ProduceData() error {
wg := sync.WaitGroup{}
// crawl spaces
wg.Add(1)
go func() {
wg.Go(func() {
for _, d := range dirs {
dp.evaluateNodeDir(d)
}
wg.Done()
}()
})
// crawl trash
wg.Add(1)
go func() {
wg.Go(func() {
dp.evaluateTrashDir()
wg.Done()
}()
})
// crawl blobstore
if !dp.skipBlobs {
wg.Add(1)
go func() {
wg.Go(func() {
bs, err := dp.lbs.List()
if err != nil {
fmt.Println("error listing blobs", err)
@@ -102,8 +97,7 @@ func (dp *DataProvider) ProduceData() error {
for _, bn := range bs {
dp.Events <- BlobData{BlobPath: dp.lbs.Path(bn)}
}
wg.Done()
}()
})
}
// wait for all crawlers to finish

View File

@@ -227,13 +227,11 @@ func listFolder(path string, ch chan<- string, workers chan struct{}) error {
for _, child := range children {
if child.IsDir() {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
if err := listFolder(filepath.Join(path, child.Name()), ch, workers); err != nil {
fmt.Println("error listing", path, err)
}
}()
})
}
if _versionRegex.MatchString(child.Name()) {

View File

@@ -526,9 +526,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) error {
s.Log.Info().Msg("starting graceful shutdown")
start := time.Now()
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
ctx, cancel := context.WithTimeout(context.Background(), _defaultShutdownTimeoutDuration)
defer cancel()
s.Log.Debug().Msg("starting runtime listener shutdown")
@@ -537,7 +535,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) error {
return
}
s.Log.Debug().Msg("runtime listener shutdown done")
}()
})
// shutdown services in the order defined in the config
// any services not listed will be shutdown in parallel afterwards

View File

@@ -139,9 +139,7 @@ func (av Antivirus) Run() error {
wg := sync.WaitGroup{}
for range av.config.Workers {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
EventLoop:
for {
@@ -170,7 +168,7 @@ func (av Antivirus) Run() error {
break EventLoop
}
}
}()
})
}
wg.Wait()

View File

@@ -146,9 +146,7 @@ func AutoAcceptShares(ev events.ShareCreated, autoAcceptDefault bool, l log.Logg
wg := sync.WaitGroup{}
for i := 0; i < maxConcurrency; i++ {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for userID := range work {
if !autoAcceptShares(ctx, userID, autoAcceptDefault, vs) {
@@ -179,7 +177,7 @@ func AutoAcceptShares(ev events.ShareCreated, autoAcceptDefault bool, l log.Logg
}().Interface("status", resp.GetStatus()).Str("userid", userID.GetOpaqueId()).Msg("unexpected status code while accepting share")
}
}
}()
})
}
// Wait for all goroutines to finish

View File

@@ -114,9 +114,7 @@ EventLoop:
break EventLoop
}
// TODO: needs to be replaced with a worker pool
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
switch e := evt.Event.(type) {
case events.SpaceShared:
@@ -134,7 +132,7 @@ EventLoop:
case events.SendEmailsEvent:
s.sendGroupedEmailsJob(e, evt.ID)
}
}()
})
if s.stopped.Load() {
break EventLoop

View File

@@ -109,9 +109,7 @@ func (pps *PostprocessingService) Run() error {
wg := sync.WaitGroup{}
for range pps.c.Workers {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
EventLoop:
for {
@@ -149,7 +147,7 @@ func (pps *PostprocessingService) Run() error {
}
}
}
}()
})
}
wg.Wait()