Skip to content

Commit 11688f7

Browse files
STOYAN KIROVSTOYAN KIROV
authored andcommitted
Replace channels with wait groups
1 parent 0727410 commit 11688f7

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"log"
1010
"net/http"
1111
"os"
12+
"sync"
1213
"time"
1314
)
1415

@@ -78,27 +79,30 @@ func main() {
7879
}
7980

8081
var allHistoryUrls []string
81-
historicResponses := make(chan []byte)
82+
var wg sync.WaitGroup
83+
historicResponses := make([][]byte, len(historyItems))
8284
for i, hi := range historyItems {
8385
historyUrl := fmt.Sprintf("https://web.archive.org/web/%vif_/%v", hi.Timestamp, *url)
8486

8587
if *printUrls {
8688
allHistoryUrls = append(allHistoryUrls, historyUrl)
8789
continue
88-
return
8990
}
9091

92+
wg.Add(1)
9193
if i%MAX_REQUESTS_COUNT == 0 {
9294
time.Sleep(PAUSE_INTERVAL * time.Second)
9395
}
9496

9597
go func() {
96-
historicResponses <- get(historyUrl)
98+
historicResponses = append(historicResponses, get(historyUrl))
99+
wg.Done()
97100
}()
98101
}
102+
wg.Wait()
99103

100104
uniqueResponses := make(map[[20]byte][]byte)
101-
for res := range historicResponses {
105+
for _, res := range historicResponses {
102106
if *output != "" || *unique {
103107
uniqueResponses[sha1.Sum(res)] = res
104108
}

0 commit comments

Comments
 (0)