Open
Description
Hey @loong - love this repo and its helping me improve my Go skills
After adding what I think is the desired solution the tests continue to fail. Even when I include a 5 second delay.
func Crawl(url string, depth int, wg *sync.WaitGroup) {
+ rateLimit := time.Second * 5
+ throttle := time.NewTicker(rateLimit)
+ defer throttle.Stop()
defer wg.Done()
if depth <= 0 {
return
}
body, urls, err := fetcher.Fetch(url)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("found: %s %q\n", url, body)
wg.Add(len(urls))
for _, u := range urls {
// Do not remove the `go` keyword, as Crawl() must be
// called concurrently
+ <-throttle.C // rate limit client calls
go Crawl(u, depth-1, wg)
}
return
}

Go version go version go1.21.0 darwin/amd64
Please let me know if I'm missing something here. Thanks!
Metadata
Metadata
Assignees
Labels
No labels