Our great sponsors
-
go-concurrency-exercises
Hands on exercises with real-life examples to study and practice Go concurrency patterns. Test-cases are provided to verify your answers.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
I have started to try to learn concurrency in Go. I have read this and now started to try to solve this one
As a help it recommends to check this rate limiter and also it said that the solution could be done in three lines.
// Crawl uses `fetcher` from the `mockfetcher.go` file to imitate a // real crawler. It crawls until the maximum depth has reached. func Crawl(url string, depth int, wg *sync.WaitGroup) { 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 go Crawl(u, depth-1, wg) } return } func main() { var wg sync.WaitGroup wg.Add(1) Crawl("http://golang.org/", 4, &wg) wg.Wait() }