Skip to content

Commit

Permalink
refactor: Using shadowing for launching goroutine in a loop
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed May 4, 2022
1 parent ee49096 commit a7c719e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/crud/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@ func (a App) List(ctx context.Context, request provider.Request, message rendere
})

for index, item := range files {
func(item absto.Item, index int) {
wg.Go(func() {
aggregate, err := a.exifApp.GetAggregateFor(ctx, item)
if err != nil {
logger.WithField("fn", "crud.List").WithField("item", item.Pathname).Error("unable to read: %s", err)
}
index := index
item := item

wg.Go(func() {
aggregate, err := a.exifApp.GetAggregateFor(ctx, item)
if err != nil {
logger.WithField("fn", "crud.List").WithField("item", item.Pathname).Error("unable to read: %s", err)
}

renderItem := provider.StorageToRender(item, request)
renderItem.Aggregate = aggregate
renderItem := provider.StorageToRender(item, request)
renderItem.Aggregate = aggregate

items[index] = renderItem
})
}(item, index)
items[index] = renderItem
})
}

wg.Wait()
Expand Down

0 comments on commit a7c719e

Please sign in to comment.