Skip to content

Commit 1511c91

Browse files
authored
Use WaitGroup.Go for remaining manual Add/Done patterns (#4956)
## Summary - Replace remaining `wg.Add`/`wg.Done`/`go` patterns with `wg.Go(...)` in `libs/dagrun`, `libs/filer`, and `libs/sync` - These weren't caught by the `use-waitgroup-go` revive rule because they call `Done()` inside separate functions rather than inline ## Test plan - [x] `go test ./libs/dagrun/ ./libs/filer/ ./libs/sync/` passes This pull request was AI-assisted by Isaac.
1 parent 102720b commit 1511c91

3 files changed

Lines changed: 5 additions & 12 deletions

File tree

libs/dagrun/dagrun.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,8 @@ func (g *Graph) Run(pool int, runUnit func(node string, failedDependency *string
176176
done := make(chan doneResult, len(in))
177177

178178
var wg sync.WaitGroup
179-
wg.Add(pool)
180179
for range pool {
181-
go runWorkerLoop(&wg, ready, done, runUnit)
180+
wg.Go(func() { runWorkerLoop(ready, done, runUnit) })
182181
}
183182

184183
for _, n := range initial {
@@ -226,8 +225,7 @@ type task struct {
226225
failedFrom *string
227226
}
228227

229-
func runWorkerLoop(wg *sync.WaitGroup, ready <-chan task, done chan<- doneResult, runUnit func(string, *string) bool) {
230-
defer wg.Done()
228+
func runWorkerLoop(ready <-chan task, done chan<- doneResult, runUnit func(string, *string) bool) {
231229
for t := range ready {
232230
success := runUnit(t.n, t.failedFrom)
233231
if t.failedFrom != nil {

libs/filer/workspace_files_cache.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,14 @@ func newWorkspaceFilesReadaheadCache(ctx context.Context, f Filer) *cache {
206206
}
207207

208208
for range kNumCacheWorkers {
209-
c.wg.Add(1)
210-
go c.work(ctx)
209+
c.wg.Go(func() { c.work(ctx) })
211210
}
212211

213212
return c
214213
}
215214

216215
// work until the queue is closed.
217216
func (c *cache) work(ctx context.Context) {
218-
defer c.wg.Done()
219-
220217
for e := range c.queue {
221218
e.execute(ctx, c)
222219
}

libs/sync/sync.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,9 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) {
121121
if opts.OutputHandler != nil {
122122
ch := make(chan Event, MaxRequestsInFlight)
123123
notifier = &ChannelNotifier{ch}
124-
outputWaitGroup.Add(1)
125-
go func() {
126-
defer outputWaitGroup.Done()
124+
outputWaitGroup.Go(func() {
127125
opts.OutputHandler(ctx, ch)
128-
}()
126+
})
129127
} else {
130128
notifier = &NopNotifier{}
131129
}

0 commit comments

Comments
 (0)