-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
fetch.go
37 lines (33 loc) · 759 Bytes
/
fetch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package blockbuilder
import (
"context"
"net/http"
)
func getLists(ctx context.Context, client *http.Client, urls []string) (
uniqueResults map[string]struct{}, errs []error) {
chResults := make(chan []string)
chError := make(chan error)
for _, url := range urls {
go func(url string) {
results, err := getList(ctx, client, url)
chResults <- results
chError <- err
}(url)
}
uniqueResults = make(map[string]struct{})
listsLeftToFetch := len(urls)
for listsLeftToFetch > 0 {
select {
case results := <-chResults:
for _, result := range results {
uniqueResults[result] = struct{}{}
}
case err := <-chError:
listsLeftToFetch--
if err != nil {
errs = append(errs, err)
}
}
}
return uniqueResults, errs
}