summaryrefslogtreecommitdiff
path: root/workers.go
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-26 21:59:10 -0400
committerdemo <demo@antix1>2026-05-26 21:59:10 -0400
commitd7beae73c248e5601e0fce78dca0b65cb6abd066 (patch)
treeb972e69dc3cadd68505c3adac5de39f37b3ea21c /workers.go
parent00f30b53a746d45586c59773614f4c780880a788 (diff)
fix: make sure all workers terminate by the end
Diffstat (limited to 'workers.go')
-rw-r--r--workers.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/workers.go b/workers.go
index ce1001e..01c6888 100644
--- a/workers.go
+++ b/workers.go
@@ -29,17 +29,26 @@ func workers(startURL url.URL, maxConcurrency, maxURLs int) {
// Create maxConcurrency worker goroutines to demultiplex from
// the urls channel (unseen links.)
- for range maxConcurrency {
+ for i := range maxConcurrency {
wg.Go(func() {
+ loop:
for u := range urls {
batch := getBatch(u)
select {
case <-ctx.Done():
- return
+ break loop
default:
- go func() { worklist <- batch }()
+ go func() {
+ select {
+ case <-ctx.Done():
+ return
+ case worklist <- batch:
+ }
+ }()
}
}
+
+ fmt.Printf("terminating %d\n", i+1)
})
}
@@ -66,6 +75,8 @@ loop:
}
}
+ close(urls)
+
cancel()
wg.Wait()
}