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