Skip to content

Commit

Permalink
Remove sync.WaitGroup usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayan George committed Sep 25, 2017
1 parent 485e078 commit d5b60ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
16 changes: 3 additions & 13 deletions adstxt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"net/http"
"strings"
"sync"
)

type AdsTxt struct {
Expand Down Expand Up @@ -115,13 +114,7 @@ type fetchresult struct {
Contents string
}

func fetch(url string, rc chan<- AdsTxt, wg *sync.WaitGroup) {
defer func() {
if wg != nil {
wg.Done()
}
}()

func fetch(url string, rc chan<- AdsTxt) {
resp, err := http.Get(url)

if err != nil {
Expand Down Expand Up @@ -152,16 +145,13 @@ func Fetch(ctx context.Context, urls ...string) ([]AdsTxt, error) {
go func() {
// make sure we close we our ads channel on return.
defer close(ads)
results := make(chan AdsTxt, len(urls))
defer close(results)

wg := sync.WaitGroup{}
wg.Add(len(urls))
results := make(chan AdsTxt)

// dispatch web queries.
go func() {
for _, url := range urls {
go fetch(url, results, &wg)
go fetch(url, results)
}
}()

Expand Down
8 changes: 6 additions & 2 deletions adstxt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,12 @@ func TestFetchURL(t *testing.T) {
delete(srcmap, ads[i].Source)
}


for i := range a
if len(ads) > 0 {
t.Logf("Responses:")
for i := range ads {
t.Logf("> %s", ads[i].Source)
}
}

if len(srcmap) > 0 {
t.Logf("We did not get a response from the following sources:")
Expand Down

0 comments on commit d5b60ce

Please # to comment.