summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-23 10:20:24 -0400
committerdemo <demo@antix1>2026-05-23 10:20:24 -0400
commitbc4948442d8eb571ca94fd79898c19b6c204d591 (patch)
treee900e751db2cb5cfa5b029a95fbda548293e0790 /main.go
parent212227b6719bed8b5e78db42a7da40b0491181e5 (diff)
feat: add semaphore to throttle concurrent GET requests
Diffstat (limited to 'main.go')
-rw-r--r--main.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/main.go b/main.go
index db53d69..ed203d5 100644
--- a/main.go
+++ b/main.go
@@ -32,6 +32,8 @@ func main() {
worklist <- []url.URL{*startURL}
}()
+ sem := make(chan struct{}, *maxConcurrency)
+
seen := make(map[url.URL]bool)
for list := range worklist {
for _, u := range list {
@@ -40,6 +42,9 @@ func main() {
seen[u] = true
go func() {
+ sem <- struct{}{}
+ defer func() { <-sem }()
+
worklist <- crawl(u)
}()
}