summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-26 18:19:34 -0400
committerdemo <demo@antix1>2026-05-26 18:19:34 -0400
commit5cc1fc597f13c2f7c781f45b5f37169958752b04 (patch)
tree42dcc2587a2841287e132111bd9dde1600280f5d
parent35e2864220e493f8aa77b5808b0a26674f4f3403 (diff)
feat: implement maxConcurrency using a buffered channel 'sema'
-rw-r--r--classic.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/classic.go b/classic.go
index ef138e2..bb22b0b 100644
--- a/classic.go
+++ b/classic.go
@@ -23,6 +23,7 @@ func classic(startURL url.URL, maxConcurrency, maxURLs int) {
ctx, cancel := context.WithCancel(context.Background())
var wg sync.WaitGroup
+ sema := make(chan struct{}, maxConcurrency)
loop:
for ; numPendingSends > 0; numPendingSends-- {
@@ -42,7 +43,9 @@ loop:
select {
case <-ctx.Done():
return
- case worklist <- getBatch(u):
+ case sema <- struct{}{}:
+ defer func() { <-sema }()
+ worklist <- getBatch(u)
}
})
}