summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-31 00:08:43 -0400
committerdemo <demo@antix1>2026-05-31 00:09:19 -0400
commit60cc56edc55290cd0999bd859a1dfa2c8dbc96d5 (patch)
tree13a2295d26b8ac74e00b264c73586ffc6342e78c
parent94093807a03d295f82bcec82244f68fb10efe312 (diff)
feat: use for-select instead of range
-rw-r--r--workers.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/workers.go b/workers.go
index 02d7d7d..db22986 100644
--- a/workers.go
+++ b/workers.go
@@ -33,23 +33,23 @@ func workers(startURL url.URL, maxConcurrency, maxURLs, maxDepth int) {
// the urls channel (unseen links.)
for i := range maxConcurrency {
wg.Go(func() {
- for p := range packets {
- batch := getBatch(p.url)
-
- // Convert URLs to Packets. In the
- // process, bump up the depth by 1.
- ps := convertToPackets(batch, p.depth+1)
-
+ for {
select {
case <-ctx.Done():
fmt.Printf("exiting early %d\n", i+1)
- return
- default:
+ case p, ok := <-packets:
+ if !ok {
+ fmt.Printf("exiting because packets is closed %d\n", i+1)
+ }
+
+ batch := getBatch(p.url)
+
+ // Convert URLs to Packets. In the
+ // process, bump up the depth by 1.
+ ps := convertToPackets(batch, p.depth+1)
go func() { worklist <- ps }()
}
}
-
- fmt.Printf("terminating %d\n", i+1)
})
}