Skip to content

Commit

Permalink
Increment the waitGroup outside of the go routines
Browse files Browse the repository at this point in the history
  • Loading branch information
m7kvqbe1 committed Jul 9, 2024
1 parent cd3054a commit c4284f9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type Scraper struct {
}

func (s *Scraper) sendText(number string) {
s.waitGroup.Add(1)
defer s.waitGroup.Done()

key := os.Getenv("SMS_KEY")
Expand Down Expand Up @@ -69,7 +68,6 @@ func (s *Scraper) sendText(number string) {
}

func (s *Scraper) fetch() {
s.waitGroup.Add(1)
defer s.waitGroup.Done()

c := colly.NewCollector(
Expand Down Expand Up @@ -116,6 +114,7 @@ func (s *Scraper) success() {

phoneNumbers := strings.Split(os.Getenv("PHONE_NUMBERS"), ",")
for _, number := range phoneNumbers {
s.waitGroup.Add(1)
go s.sendText(number)
}

Expand All @@ -140,6 +139,7 @@ func (s *Scraper) scrapeLoop() {
case <-s.done:
return
case <-ticker.C:
s.waitGroup.Add(1)
go s.fetch()
}
}
Expand Down

0 comments on commit c4284f9

Please sign in to comment.