Skip to content

Commit

Permalink
Fixes #65
Browse files Browse the repository at this point in the history
  • Loading branch information
haxorof committed Jun 12, 2021
1 parent 1265ce3 commit 5b448fb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 2 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 5b448fb

Please sign in to comment.