From 5b448fb7c9d0d7d02dc7483bd6f70520ed047a5b Mon Sep 17 00:00:00 2001 From: Bjorn Oscarsson Date: Sat, 12 Jun 2021 19:06:59 +0200 Subject: [PATCH] Fixes #65 --- main.go | 6 ++---- worker.go | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index e1b4589..457860b 100644 --- a/main.go +++ b/main.go @@ -88,10 +88,8 @@ func main() { for _, q := range queries { // Create a new worker and start it in its own goroutine. - // type key string - // const wgKey key = "wg" - w = NewWorker(context.WithValue(ctx, contextKey("wg"), wg), q) - go w.Start(service) + w = NewWorker(ctx, q) + go w.Start(service, wg) } // Register the handler. diff --git a/worker.go b/worker.go index 4dc48a1..ee13b6c 100644 --- a/worker.go +++ b/worker.go @@ -117,7 +117,7 @@ func (w *Worker) fetchRecords(url string) error { } // Start fetching data from specified URL -func (w *Worker) Start(url string) { +func (w *Worker) Start(url string, wg *sync.WaitGroup) { tick := func() { err := w.fetchRecords(url) if err != nil { @@ -132,7 +132,6 @@ func (w *Worker) Start(url string) { for { select { case <-w.ctx.Done(): - wg, _ := w.ctx.Value("wg").(*sync.WaitGroup) wg.Done() w.log.Printf("Stopping worker") return