From 420fea33e5b3d955a905c087397c4f6549a867f0 Mon Sep 17 00:00:00 2001 From: Casey Marshall Date: Mon, 6 Dec 2021 15:28:25 -0600 Subject: [PATCH] chore: simplify scraper.Run Replace the WaitGroup in scraper.Run with a buffered channel. --- vervet-underground/internal/scraper/scraper.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/vervet-underground/internal/scraper/scraper.go b/vervet-underground/internal/scraper/scraper.go index 3aca089b..61724c3c 100644 --- a/vervet-underground/internal/scraper/scraper.go +++ b/vervet-underground/internal/scraper/scraper.go @@ -8,7 +8,6 @@ import ( "io/ioutil" "net/http" "net/url" - "sync" "time" "github.com/pkg/errors" @@ -101,24 +100,19 @@ func Clock(c func() time.Time) Option { // Run executes the OpenAPI version scraping on all configured services. func (s *Scraper) Run(ctx context.Context) error { scrapeTime := s.timeNow().UTC() - var wg sync.WaitGroup - errCh := make(chan error) + errCh := make(chan error, len(s.services)) for i := range s.services { svc := s.services[i] - wg.Add(1) go func() { - defer wg.Done() errCh <- s.scrape(ctx, scrapeTime, svc) }() } - go func() { - wg.Wait() - close(errCh) - }() var errs error - for err := range errCh { + for _ = range s.services { + err := <-errCh errs = multierr.Append(errs, err) } + close(errCh) return errs }